Disable Mail Notification from Cron

How to stop receiving email alert from cron on any unix / linux environment

Have you ever use your Raspberry Pi terminal session and you see following message randomly?

You have new mail in /var/mail/pi

Maybe you’re wondering who’s sending these emails. To know that, you can type mail to check your inbox. If you see several messages like following line, then it’s caused by cron job.

$ mail
"/var/mail/pi": 2047 messages 2047 new
>N   1 Cron Daemon        Wed Jan 13 18:50  22/681   Cron <pi@retropie> /home/pi/go/bin/gonetweet
 N   2 Cron Daemon        Wed Jan 13 18:51  21/3540  Cron <pi@retropie> /home/pi/autotweet.sh
 N   3 Cron Daemon        Wed Jan 13 18:51  22/681   Cron <pi@retropie> /home/pi/go/bin/gonetweet
 N   4 Cron Daemon        Wed Jan 13 18:52  22/681   Cron <pi@retropie> /home/pi/go/bin/gonetweet
 N   5 Cron Daemon        Wed Jan 13 18:52  21/3540  Cron <pi@retropie> /home/pi/autotweet.sh

To stop cron sending you emails, you can just add >/dev/null 2>&1 to the end of your cron job.

To do that, open your cron jobs.

crontab -e

Then append >/dev/null 2>&1 for each job. Here is an example of my cron jobs.

* * * * * /home/pi/autotweet.sh >/dev/null 2>&1
* * * * * /home/pi/go/bin/gonetweet >/dev/null 2>&1

Afther that, save the crontab file. Then you’ll never receive mail notification again from cron.

References