October 6th, 2008 |
Using cron and anacron in Ubuntu Linux
One of the LTSP scipts I was working on has a set of cronjobs that need to be entered into the cron manager for repeated execution every hour. I figured the easiest way to set up a task that needs to repeat every hour is to create a script and drop it into /etc/cron.hourly, letting the crontab take care of the rest. In theory, one doesn't even have to reload the crontab since that is done automatically every hour, day and week. I spent a good half day trying to figure out why my cron jobs were just not being executed, thinking first it was my scripting, then my cron installation, and finally concluding crontab was somehow not working properly. After talking with someone on IRC about the issue, it turned out my script was being ignored by crontab because it had the following missing from it:
set -e
Now I know not all scripts need this, but just in case someone else runs into a problem where they're script isn't executing in crontab, the solution is to add the headers:
#! /bin/sh
set -e


