{ 34 comments… read them below or add one }

1 Renish Ladani August 2, 2007 at 1:57 pm

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

Reply

2 Henrik Johansen August 3, 2007 at 8:36 am

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

Reply

3 Anand Sharma August 30, 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.

Reply

4 kthx August 3, 2011 at 4:01 am

Hahaha just stop there for a while lol….

Reply

5 Gopal January 25, 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

Reply

6 Prolific Programmer February 1, 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.

Reply

7 Matt Balloon March 7, 2008 at 3:23 pm

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

Reply

8 Phil October 12, 2008 at 12:10 pm

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

Reply

9 Sebastián Perrone December 10, 2008 at 5:32 pm

I try MAILTO environment var and work ok. Thanks for help !

Reply

10 slowpoison June 22, 2009 at 8:58 pm

Is it MAILTO or EMAILTO?
Only MAILTO worked for me. I think EMAILTO is wrong.

Reply

11 nixCraft June 22, 2009 at 9:38 pm

@ slowpoison

Thanks for the heads-up.

Reply

12 edward baddouh August 10, 2009 at 1:27 pm

It’ll be better if you redirect only the std output to /dev/null instead redirecting both (stdout & stderr). This way only commands with failure exit status will be delivered.


* * * * /path/to/script.sh > /dev/null

regards,

Reply

13 Petr Topiarz alias kolaloka March 12, 2010 at 2:43 pm

Thank you Edward,
your “> /dev/null” was the only option that did the job for me. I run and adminster 3 servers with OpenBSD 4.3-5 and the cron did not like any other stuff but what you wrote. Thanks a lot. You saved me a lot of work.
Peter

Reply

14 Anoni Mouse May 9, 2010 at 1:35 pm

It is not required to restart cron to effect changes to your crontab. Each time cron wakes up, it checks to see if the crontab has changed, and if so cron reparses it.

Reply

15 Bud June 13, 2010 at 10:57 pm

Thank you OP and Anand Sharma

Reply

16 Frank June 26, 2010 at 8:22 am

I would like to know where I can adjust the email address of cron’s mail? Apparently I set an email address somewhere when I installed the server, but I’m unable to find where I can adjust that email address. I’m running debian lenny. Can someone help me here?

Reply

17 Fredrik August 3, 2010 at 10:24 am

@Frank

Sure, use the MAILTO=”” trick, just don’t put “”

MAILTO=”frank@example.com”

Reply

18 Chris January 5, 2011 at 5:52 pm

Hi Vivek, great tip, thank you!

The correct way to restart crond in HP-UX is:

# /sbin/init.d/cron stop
# /sbin/init.d/cron start

Best regards.

Reply

19 Ilker March 12, 2011 at 6:46 am

Hi,
I wrote to the top of my crontab file
MAILTO=”myadress@gmail.com”

and the outputs of commands are not coming to my gmail adress. Why?

Thank you.

Reply

20 Rosario April 15, 2011 at 6:11 pm

@IIker, Have a look at your

/etc/postfix/sender_canonical
/etc/aliases

and reload with

/etc/postfix/postmap sender_canonical

/etc/postalias aliases

with aliases you can send mails to root and other addresses without putting it in the MAILTO in crontab. That’s how I was told to do it and it works on my servers.

Reply

21 kthx August 3, 2011 at 4:02 am

MAILTO=”” is the best solution :P

Thanks for the tip ;)

Reply

22 Howard January 31, 2012 at 2:39 pm

Will this work for the at command as well?
I’m trying to setup a series of commands that check for a condition and then reschedule themselves until it’s not true. The problem is every run sends an email to root, I need to stop that.

Reply

23 Mike February 7, 2012 at 12:43 am

Thanks for the tip, works great to disable cron emails.

Reply

24 Mickael August 24, 2012 at 3:00 am

Hi Vivek Gite,

Thank you for your post.

You can use several times the MAILTO variable in order to enable/disable e-mail sending to specific CRON job.

# Disable e-mail sending
MAILTO=""
* * * * * /bin/echo "Test email with MAILTO=\"\""
# Send e-mail to e-mail-1@domain.com
MAILTO="e-mail-1@domain.com"
* * * * * /bin/echo "Test email with MAILTO=\"e-mail-1@domain.com\""
# Send e-mail to e-mail-2@domain.com
MAILTO="e-mail-2@domain.com"
* * * * * /bin/echo "Test email with MAILTO=\"e-mail-2@domain.com\""
However, multi e-mail in MAILTO generate for me the "(CRON) error (bad mailto)" (in /var/log/syslog)
(Linux u-server-3-guest-2 2.6.38-10-virtual #46-Ubuntu SMP Tue Jun 28 17:54:41 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
)
# The following does not work, but should, if somebody know why
MAILTO="e-mail-1@domain.com, e-mail-2@domain.com"
* * * * * /bin/echo "Test email with MAILTO=\"e-mail-1@domain.com, e-mail-2@domain.com\""

Cheers,
Mickael

Reply

25 Varun Verma January 9, 2013 at 10:37 pm

Works like a charm. Thanks for sharing.

Reply

26 Rick March 20, 2013 at 9:48 pm

Hi,

I have another question for you. I want to set a cronjob which should be doing following:
checking a error file if generated every night in a specific directory and if there is one then sending to 5 users email id?

I think this should be done by creating a shell script and scheduling it every night.

Thanks a lot

Reply

27 Mickael March 21, 2013 at 4:09 am

Hi Rick,

I must say, it is not really a question about CRON, you are asking for writing a bash script?
Could you give your current scipt and if you have an issue with CRON notification, you could details your problem.

Cheers,
Mickael

Reply

28 Rick March 21, 2013 at 2:55 pm

@Michael

Thanks for replying here it is

#!/bin/sh
err_log_dir=”/apps/Load/DataLoad/DataLoadLogs”
logfile=”/apps/Load//DataLoad/DataLoadLogs/Mail_Log.log”

count=$(ls -1 ${err_log_dir}/*.err 2>/dev/null | wc -l)
if [ $count != 0 ]
then
echo “ERROR: There was an error in loading data” >> ${logfile}
MAILTO=”xysz.com” >> ${logfile}
else
echo “No Error file was created.” >> ${logfile}
exit
fi

Reply

29 Rick March 25, 2013 at 4:22 pm

Hi,

Any one can reply to my above query?

Thanks

Reply

30 anonymous October 3, 2013 at 8:26 pm

Try ‘if [ ${count} -ne 0 ] ; then ….

Reply

31 fireskyer October 21, 2013 at 12:21 pm

How can i surpress certain
Output from crontab ?

for example:
stdin: is not a tty line

Reply

32 ismail sebbane February 21, 2014 at 3:04 pm

This solution suits me ^^
I use MailTo = “myemail” at the beginning of the crontab-e line to receive all email on my mailbox
For cron which I do not wish to receive mails I add> / dev / null 2> & 1 at the end of the cron

Thank you.

Reply

33 Tim June 5, 2014 at 10:15 pm

I tried this, but I receive an error:

MAILTO=””
crontab: error on previous line; unexpected character found in line.

Reply

34 ankit jain August 19, 2014 at 1:03 pm

hi,

Can u please tell me if i use MAILTO=”” option to stop receiving mails from cron then
where this mails will be stored.?
Will it go in trash or in queue ?

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: