Monday 9 October 2017

macos - crontab - /bin/sh: wget: command not found


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

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...