About Linux FAQ

Browse More FAQs:

Disable the mail alert by crontab command

Posted by Vivek Gite [Last updated: September 7, 2007]

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:

Discussion on This FAQ

  1. Renish Ladani Says:

    I tried above thing and it works on my server
    Thanks.
    -Renish

  2. Henrik Johansen Says:

    Setting MAILTO="" in your crontab disables the sending of emails aswell.

  3. Anand Sharma Says:

    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.

  4. Gopal Says:

    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

  5. Prolific Programmer Says:

    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.

  6. Matt Balloon Says:

    I used your tip for my openads installation, thanks, I think cronjobs are pretty complicated things

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!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , ,

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.