Monday, October 24, 2011

Cron error email notification in Ubuntu

A member of the team realized one of the cron processes was failing but we were not getting any alerts.

While I favor the use of LogMonitor for absolutely everything there are simple commands you use in cron jobs for which ideally you would like to get notifications without the need of logging.

If you design your script carefully respecting the fact that error messages mut go to stderr this procedure should work:

  1. Be sure sSMTP is installed and properly configured:
    $ sudo apt-get install ssmtp
    $ sudo vi /etc/ssmtp/ssmtp.conf
  2. Add a line at the beginning of crontab stating who the error email should me sent to:
    $ crontab -e
    0 22 * * * /usr/sbin/ > /dev/null

Note the redirection of stdout to /dev/null. You want to receive I bet just errors right?

No comments: