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?
crontab command is use to maintain crontab files for individual users.
By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append following string:
Cron Job Prevent the sending of errors and output
To prevent the sending of errors and output, add any one of the following at the end of the line for each cron job to redirect output to /dev/null.
>/dev/null 2>&1.
OR
&> /dev/null
Cron Job Example
Edit/Open your cron jobs, enter:
$ crontab -e
Append string >/dev/null 2>&1 to stop mail alert:
0 1 5 10 * /path/to/script.sh >/dev/null 2>&1
OR
0 1 5 10 * /path/to/script.sh &> /dev/null
Save and close the file. Restart the crond:
# /etc/init.d/crond restart
MAILTO variable
As pointed out by Anand Sharma, you can set MAILTO="" variable at the start of your crontab file. This will also disable email. Edit/Open your cron jobs
$ crontab -e
At the top of the file, enter:
MAILTO=""
Save and close the file.
See also:
- Email FAQ to a friend
- Printable version
- Rss Feed
- Last Updated: 6-22-09


{ 10 comments… read them below or add one }
I tried above thing and it works on my server
Thanks.
-Renish
Setting
MAILTO=""in your crontab disables the sending of emails aswell.If your crontab has huge number of scripts to run it would be cumbersome to append >/dev/numm 2>&1 to each line. Like I have 369 scripts in my crontab. So I find it better to have the MAILTO=”" line at the start of my crontab instead.
But if you have so many cron jobs and you want disable mail alert for a few of them, while other jobs needs a mail alert, then &>/dev/null would be the best choice.
Thanks
For the csh scripts, at least on every system I have access to, to redirect stderr, you need to put >& /dev/null after the command, not &> as indicated by the note.
I used your tip for my openads installation, thanks, I think cronjobs are pretty complicated things
If you want the crontab to run daily, weekley, monthly etc.. a good shortcut is to use the variables
@daily, @weekley etc…
It saves you accidently missing out a * and getting thousands of emails by mistake
http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5
for a full list of them
I try MAILTO environment var and work ok. Thanks for help !
Is it MAILTO or EMAILTO?
Only MAILTO worked for me. I think EMAILTO is wrong.
@ slowpoison
Thanks for the heads-up.