MacOS – Cron script not executing on Mavericks

cronmacos

I have configured a user crontab file as follows:

*/2 * * * * /Users/[my user]/Dropbox/htdocs/auto-update.sh

But it won't execute. I waited for, like, 10-15 minutes. Why?

Command auto-update.sh runs easily if executed manually. How can I break apart the chain of execution and get my script running from cron?

Best Answer

The environment a cron job runs in is quite a bit different from an interactive shell; it's likely that the script is running, but not successfully. One of the biggest differences are that for cron jobs, the default PATH is just "/usr/bin:/bin", so if you use any commands that aren't in /usr/bin or /bin, they won't be found unless your script either sets its own PATH, or supplies explicit paths to commands. The other big difference is simply that it's not connected to an interactive session, so if it tries to do anything interactive (read from the terminal, etc) that'll fail. Try changing the cron entry to:

*/2 * * * * /Users/[my user]/Dropbox/htdocs/auto-update.sh >>/tmp/auto-update.log 2>&1

...and see if anything informative shows up in the log.