cronjobber: cron job wrapper
Sources and Installation
Theory of Operation
Have you ever seen these problems with cron jobs?
- Frequent emails that nobody reads
- Output redirection to /dev/null
- Hundreds of the same job accumulate; subsequent machine crash
- Thundering herds as hundreds of machines always kick off the same job at once
- Job runs fine from your login environment, but not from cron environment
- Job stops working, but there are no mails or logs to help troubleshoot
These problems are seen everywhere, and various workarounds are made up on
For example, the problem of too much mail is usually "solved" by redirecting
output to /dev/null.
Of course this means that jobs can silently fail without any trace of what went
Cronjobber solves these problems in a systematic way:
- All job output is kept in rotated log files. Rotation age is user-defined.
- Mail is only sent when something significant happens. User-written checker script defines "significant" based on job output and exit value.
- Mail can be sent to someone other than the crontab owner.
- Locks prevent multiple instances of a job from running at once.
- Optional timeouts can signal long-running jobs.
- Optional random backoffs thin thundering herds.
- Detects if a job didn't finish because of a system crash.
- Sets up predictable environment for testing.
cronjobber is implemented in a single C source file which should be portable to all posix systems.
My development system is FreeBSD.
cronjobber compiles and has been lightly tested on Darwin and OpenBSD.