I am completely baffled by the behaviour of cron under Mac OS 10.6 Server. I am trying to run two scripts in a cronjob like this:
00 16 * * * /Users/myusername/script.sh
04 16 * * * /Users/myusername/crontest.sh
While ‘script.sh’ contains a wget command:
#!/bin/sh
wget -r -l3 --no-parent -nc -A ".shtml" 'http://some.url/somethingelse/'
‘crontest.sh’ contains just a test script:
echo "hi" >> /Users/myusername/crontest.txt
Problem is, ‘script.sh’ does not fire, but ‘crontest.sh’ does. What could be the cause of the wget script not firing? Do the scripts require a specific encoding? Does cron write a log file somewhere?
(I tested the wget command by itself in the shell, where it works fine.)
cron runs scripts with a very minimal environment. In particular, its PATH doesn’t contain all of the usual binaries directories, just /usr/bin and /bin, so any commands in other binaries directories (like wget) will not be available.
There are several ways to fix this. One option is to have your script give the complete path of wget:
(or whatever its actual path is — use
which wgetto find out.)Another is to explicitly set PATH in the script:
(or whatever PATH you normally use; be sure it includes wget’s location.)
Or you can set the PATH in your crontab: