Tech Blog :: Cron Wrapper Script


Nov 14 '10 12:22am
Tags

Cron Wrapper Script

I was having issues with a server's crontab, but the complexity of the cron commands (with logging and error-catching added to each) made it hard to debug. So I wrote this general cron wrapper script. (It's built for Ubuntu Linux, should work in any bash shell, but haven't tested it in other environments.)
To use, extract cron-wrap.sh somewhere on the server. Then in your crontab, you call it like so (this example runs every minute):

WRAPPER=/path/to/cron-wrap.sh
CRON_LOG=/var/log/cron.log
 
* * * * * $WRAPPER -d "Doing something" -s "/usr/local/dosomething.sh" -l $CRON_LOG &>> $CRON_LOG

It'll collect all output (regular and error), then dump it as a block into the specified log file.

The trailing 2>> $CRON_LOG in the example will catch errors in the wrapper script itself; errors in the command are caught by the script.

Run cron-wrap.sh by itself to see the usage. (There are 3 one-letter arguments.)

AttachmentSize
cron-wrap.tar4 KB

Post new comment

Don't bother putting in spam links. They'll be set to rel=nofollow and will be removed and reported as spam shortly after submitting.

The content of this field is kept private and will not be shown publicly.
CAPTCHA
Are you human?