Published on 2013-02-14 by John Collins. Please follow me on Twitter for more:
Recently I found myself being tormented by email notifications from one of my servers that was running a PHP script via a Cron job every ten minutes. Even though the script was running successfully, I was getting an email every ten minutes containing the output of the script. So how do we suppress these emails? You have a number of options.
The MAILTO variable allows you to set the email address that the notification emails from Cron are sent to. You can suppress all emails from your Cron jobs by setting this to an empty string like so:
$ crontab -e
Now on the top of the file, add:
Then save and close the file.
The /dev/null location in Linux is a "black hole" for data: any output sent here is gone, which makes it a great candidate for suppressing output from Cron jobs.
To suppress all output (STDOUT and STDERR) from your Cron job, append > /dev/null 2>&1 to the end of your job:
$ crontab -e
*/30 * * * * command > /dev/null 2>&1
The number 2 represents the STDERR (standard error) stream, while 1 is the STDOUT (standard out) stream.
If you want to receive emails about errors only but not successes, append > /dev/null to your job to suppress output from STDOUT only:
*/30 * * * * command > /dev/null