开发者

mac os 10.6 server: crontab does not fire wget script

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:

#!/bin/sh
/usr/local/bin/wget -r -l3 --no-parent -nc -A ".shtml" 'http://some.url/somethingelse/'

(or whatever its actual path is -- use which wget to find out.)

Another is to explicitly set PATH in the script:

#!/bin/sh
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
wget -r -l3 --no-parent -nc -A ".shtml" 'http://some.url/somethingelse/'

(or whatever PATH you normally use; be sure it includes wget's location.)

Or you can set the PATH in your crontab:

PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
00 16 * * * /Users/myusername/script.sh
04 16 * * * /Users/myusername/crontest.sh


Sorry for asking the obvious: Execute flag and permissions set the same on both scripts?


Also consider making the leap to launchd. As a long-time Unix person, I initially found launchd annoyingly complex, but now that I've been using it, I find the rich feature set to be superior to trusty ole cron.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜