Get email when a cron job fails
To get an email every time a cron job, you have scheduled to run, fails:
Redirect all of your standard output to
/dev/null
or to some file.Use the
MAILTO
environment variable with a list (comma separated) of all the email addresses you want to receive the email notifications.
To avoid using the same value of MAILTO for every task you run, you can just write it in the crontab e.g.:
MAILTO="foo@bar.com"
0 5 * * * /bin/some_script > /dev/null
MAILTO="foo@bar.com" to the top of a crontab will cause any output from the cron job to be emailed. So we redirect the STDOUT to null and if any STDERR messages are present, they will get emailed to you.
Written by Andreas Loupasakis
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#