crontab Management Tips
- Avoid early morning jobs
- Personal crontab file backups
- Use @reboot
Some crond implementations support @reboot. This may allow jobs to be run when the system starts or reboots:
@reboot $HOME/bin/do-something
- Easy e-mail filtering
Jobs scheduled to run between 2AM and 3AM may run afoul daylight savings time shifts. This can be avoided by configuring systems to use the UTC timezone, or by more intelligent scripts that try to run multiple times. Something like: “try to run every hour, but only if last good run took place more than 24 hours ago”.
If paranoid, backup crontab(5) files to your home directory. This allows a $HOME backup to catch the files, and helps transition jobs to new systems.
# save crontab(5) 23 23 * * * crontab -l > $HOME/.cron.`hostname`
This scheme will work on multiple systems, but will fail if two users share the same home directory (bizarre and incredibly rare). Be sure to run Another option: wrap the crontab(1) command to save automatically into another repository. Also consider whether any at(1) jobs need to be backed up, or whether some other utility can regenerate them if lost from the system directory.
If supported by crond, set a custom MAILTO e-mail address. This allows a single e-mail filter to catch all e-mail generated from cron. Check with your mail administrator for the proper mail syntax to use; some systems use username+detail, others username-detail, and others will need to create a custom e-mail alias.
MAILTO=username+cron
Technorati Tags: Unix