Croncape wraps commands run as cron jobs to send emails only when an error or a timeout has occurred.
Out of the box, crontab can send an email when a job generates output. But a command is not necessarily unsuccessful "just" because it used the standard or error output. Checking the exit code would be better, but that's not how crontab was standardized.
Croncape takes a different approach by wrapping your commands to only send an email when the command returns a non-zero exit code.
Croncape plays well with crontab as it never outputs anything except when an issue occurs in Croncape itself (like a misconfiguration for instance), in which case crontab would send you an email.
Download the binaries or
go get github.com/symfonycorp/croncape.
When adding a command in crontab, prefix it with
[email protected] 0 6 * * * croncape ls -lsa
Note that the
MAILTO environment variable can also be defined globally in
/etc/crontab; it supports multiple recipients by separating them with a comma.
You can also customize the email sender by setting the
If you need to use "special" shell characters in your command (like
don't forget to quote it:
0 6 * * * croncape "ls -lsa | true"
Besides sending emails, croncape can also kill the run command after a given
timeout, via the
-t flag (disabled by default):
0 6 * * * croncape -t 2h ls -lsa
If you want to send emails even when commands are successful, use the
(useful for testing).
-h flag to display the full help message.
Croncape is very similar to cronwrap, with some differences:
No dependencies (cronwrap is written in Python);
Kills a command on a timeout (cronwrap just reports that the command took more time to execute);
Tries to use
Reads the email from the standard crontab
MAILTO environment variable
instead of a
For a simpler alternative, have a look at cronic.