How to test if a Crontab is working in Ubuntu CodeUnit 15 JUN 2012

Editing your cron jobs with the crontab -e command will ensure that your crontab is at least syntactically correct, by not installing it unless it is a valid cron file.

Outside of that though, it falls to you to test that your jobs are in fact running correctly. This can be achieved by piping the cron command output to a file that you control for each one of your jobs.

In practice:

00 01 * * * bash > /tmp/mycronjob.log 
00 02 * * * bash > /tmp/mycronjob.log

And in the same vein, you can check that the crontab as a whole is being executed by creating a job right at the end of the cron list that runs every minute and pipes out its output to a file that you control:

*/1 * * * * echo "Success! $(date)" >> /tmp/cronwatch.log

Note that > means rewrite the target file every time, whilst >> means append to the end of the file (and create if not exist).


Related Link:

Related Posts:

About Craig Lotter

South African software architect and developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.