stop linux from emailing me cron errors?

Today i setup ssmtp to email me from sendmail. However what i didnt expect is that applications like cron would email me.

One of my cron scripts before backing up the db tries to create path/year/month/ and since year and month already exist i get the email

From: Root
Subject: Cron <root@myserver> /path/scripts/mysqlbackup.sh
mkdir: cannot create directory `2010': File exists
mkdir: cannot create directory `09': File exists

How do i make it stop? Its only been up for an hour so if this is the only error i'll simply just fix the script.


By default, cron mails you the output messages of a cronjob. More specifically, it saves stdout (standard output) and stderr (standard error output) of a cronjob and emails it the owner of the crontab, or the user named in the MAILTO variable in the crontab.

To prevent output reaching you, you have to make sure that stdout and stderr is not saved, but written to a file or /dev/null.

You can do this by using something like this in your job definition:

job.sh > /dev/null 2>&1

This redirects stdout to /dev/null (the '> /dev/null' part) and redirects stderr to stdout, and thus to /dev/null, too (the '2>&1' part). Odd syntax, right? ;-)

The Advanced Bash Scripting Guide has a lot more information about I/O redirection.

Alternatively, you can leave MAILTO empty (that is, define MAILTO="" in your crontab) and you will not get any mail, according to vixie-cron's manpage on RHEL4 and RHEL5.


As an alternative to redirecting the script output you can change the mail destination for a crontab file by setting MAILTO, eg. MAILTO=nobody


Fix the problem not the notification,

It's going to get you into a bad habit of just sending all notifications to >/dev/null, and sods law being what it is, you will miss something important.