0

I have Cron set up to with the following command:

* * * * * SHELL=/usr/bin/sh PATH=~/lectio-skema-til-.ics-kalender-master/script.sh

where script.sh has

#!/usr/bin/sh
cd /var/www/html/SECRET-PATH
wget "http://localhost:9002/?skole=518&elev=36015389032" -O kalender.ics

the command wget "http://localhost:9002/?skole=518&elev=36015389032" -O kalender.ics generates a kalender.ics file in /var/www/html/SECRET-PATH, and running the script.sh file works perfectly fine, however when running it with Cron, no files are generated in /var/www/html/SECRET-PATH.

I don't know what's wrong, because no errors are generated in the mail, and doing grep CRON /var/log/syslog doesn't have any errors either.

1 Answers1

2

Assuming that you run the specific script with your current user (let's say your_user), then the crontab entry for your_user should be something like this:

* * * * * /home/your_user/lectio-skema-til-.ics-kalender-master/script.sh

The script's first line indicates that an interpreter called /usr/bin/sh should be used. In my installation, there is no such executable. You should change to /bin/bash or (for a faster version) to /bin/sh which is the dash shell.

The script calls wget command. However, the PATH environment may not be set up correctly in your crontab. It is better to use full paths in commands. In my installation wget is at /usr/bin/wget. So, your script should be something like this:

#!/bin/sh
cd /var/www/html/SECRET-PATH
/usr/bin/wget "http://localhost:9002/?skole=518&elev=36015389032" -O kalender.ics
FedKad
  • 13,420