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
    Does the shell pointed to by /usr/bin/sh exist? Please, change also the command wget to full path like this: /usr/bin/wget – FedKad Jan 26 '20 at 14:21
  • 2
    Also the cron setup contains only variable declarations. No commands (scripts) to run. Also, replace the ~ with absolute path. – FedKad Jan 26 '20 at 14:25
  • PATH=~/lectio-skema-til-.ics-kalender-master/script.sh will break the shell's search path for executables (including your wget command). Why are you doing that? In fact, why are you messing withSHELL and PATH at all? – steeldriver Jan 26 '20 at 14:31
  • It says, that cron does not alert: https://crontab.guru crontab.guru - the cron schedule expression editor – Gryu Jan 26 '20 at 14:41

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
  • 10,515
  • It works now, thank you! I added home/username to the script path, and made the script.sh a separate instruction afterwards, and added the changes in this answer too. – The Colorman Jan 26 '20 at 15:13