Tech Blog :: Cron Wrapper Script
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.)
| Attachment | Size |
|---|---|
| cron-wrap.tar | 4 KB |
Google: TheBuckSt0p
Facebook: BenBuckman
LinkedIn
Github: newleafdigital
@thebuckst0p
Delicious: thebuckst0p
Drupal.org: thebuckst0p
Post new comment
Don't bother putting in spam links. They'll be set to
rel=nofollowand will be removed and reported as spam shortly after submitting.