I want to set up a crontab on my Macbook Pro running Lion. I run the usual crontab -e
and provide a quick job to see if everything is working ok ---
*/10 * * * * wget -O - -q -t 1 http://site.local/cron.php
10 minutes later I see I've got some "mail" from the system stating ---
/bin/sh: wget: command not found
I do have wget installed as I can run the program from the command line
How do I fix this error? Does my crontab or .bash_profile
require a shebang?
Answer
It's probably something to do with your environment being different when it's run as a cron job (ie the PATH
environment variable is different than what you're using from a bash terminal).
In your bash terminal, use which
to figure out which wget
is being used:
laptop [ ~ ]: which wget
/opt/local/bin/wget
Then use the full path in the cron job:
*/10 * * * * /opt/local/bin/wget -O - -q -t 1 http://site.local/cron.php
For cron jobs, I usually have it run a bash script instead of specifying the command directly in the crontab. It's a bit easier to debug and keeps the crontab a bit cleaner.
No comments:
Post a Comment