Disable the eMail Alert By Crontab Command On a Linux or Unix-like Systems

Originally published at: https://www.cyberciti.biz/faq/disable-the-mail-alert-by-crontab-command/

How do I to disable the mail alert send by crontab? When my job is executed and the jobs cannot run normally it will sent an email to root. Why do I receive e-mails to my root account from cron? How can I prevent this? How can I disable email alert sent by cron jobs on a Linux or Unix-like systems?

Cron will generate an email if your cronjob has any output. It will send that email to whichever account the crontab belongs to. If it’s a system crontab (/etc/crontab, /etc/cron.d, /etc/cron*, /var/spooll/cron/crontabs/root), the message will be send to root@localhost (redirected if there’s an alias for root in /etc/aliases). If it’s in a user’s crontab (/var/spool/cron/crontabs/loginname), the email will be sent to that user’s email address (loginname@localhost).

The way to avoid being emailed is either to write your script so that it generates no output, or shunt the output elsewhere.

Here’s a snip from my crontab, which redirects stderr and stdout

*/5 * * * *  root /usr/local/sbin/smem.cron.sh 2>&1

Depending on your system, you may need to do this:

*/5 * * * *  root /usr/local/sbin/smem.cron.sh > /dev/null 2>&1

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki