Suppressing Cron Job Email Notifications

 
Published on 2013-02-14 by John Collins. Socials: YouTube - X - Spotify - Amazon Music - Apple Podcast

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.

Using the MAILTO variable

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:

MAILTO=""

Then save and close the file.

Sending output to /dev/null

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

Example:

*/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

Updated 2023 : note that the above post was originally published in 2013, but is left here for archival purposes.