Disable the mail alert by crontab command
Q. 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?
A. 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
EMAILTO 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:
EMAILTO=""
Save and close the file.
See also:
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Other Helpful FAQs:
- HP-UX UNIX: Start / Stop and Configure Cron Services
- Ubuntu / Debian Linux: Install Monit Linux Server Monitoring Utility
- Qmail delivering mail ~/Mailbox home directories
- Run crontab Every 10 Minutes
- Delete all root mail / inbox from a shell prompt
Discussion on This FAQ
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: crontab_command, crontab_files, cron_job, EMAILTO_variable, email_account, mail_alert, stop_receiving_email



August 2nd, 2007 at 1:57 pm
I tried above thing and it works on my server
Thanks.
-Renish
August 3rd, 2007 at 8:36 am
Setting
MAILTO=""in your crontab disables the sending of emails aswell.August 30th, 2007 at 7:52 am
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.
January 25th, 2008 at 9:26 am
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
February 1st, 2008 at 2:09 pm
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.
March 7th, 2008 at 3:23 pm
I used your tip for my openads installation, thanks, I think cronjobs are pretty complicated things