Suppressing non-error e-mails from Cron tasks

10 August 2017


Overview

Cron is a task executing programme which will execute tasks at defined intervals. The process of doing so is straightforward and covered elsewhere. Cron, by default, will email (to your prompt, next time you open one) any output from the tasks. These can be errors from STDERR or just information, from STDOUT. The aim of this article is to show how to suppress the non-error emails, otherwise you might get bored of receiving multiples emails a day saying telling you that your rsync backup or smartmontools drive test completed successfully. It would be far more useful to limit these emails to only those which report errors.

The reason for this particular post is that there seem to be some quite convoluted methods of achieving this, but I found a post over at scottlinux.com and alphadevx, which was far more succinct.

Finally, this is just for the local mail delivery (via prompt), but it will obviously work if you set up postfix or another MTA.

The code

Open your Crontab with

$ crontab -e

and add this to the end of your task:

>/dev/null

It might read:

0 * * * * /path/to/script > /dev/null

That’s it.

Sources