Stop cron from emailing me

10

4

How can I stop cron from emailing me the results of jobs I schedule?

Richard Hoskins

Posted 2009-07-18T02:07:40.903

Reputation: 10 260

Answers

15

By setting the environment variable "MAILTO" as ""

Somethig like:

SHELL=/bin/bash
MAILTO=



01 * * * *  /your/path/to/script/here.sh

OscarRyz

Posted 2009-07-18T02:07:40.903

Reputation: 3 691

12

If you want a single job to stop email you simply append >/dev/null 2>&1 to it

For example:

0 * * * * /home/script >/dev/null 2>&1

Rob

Posted 2009-07-18T02:07:40.903

Reputation: 599

1If you are sure that one run will finish before the next starts, it can be worth redirecting the output to a named file rather than to /dev/null: that does give the option of checking what happened to the last run if you suspect a problem. – mas – 2009-07-18T19:02:14.510

4

Cron only emails you if there is output, either on stdout or stderr.

If it's script you've written, make it less verbose - remove unnecessary echo or print statements. Redirecting stdout to /dev/null is also a valid solution:

2 * * * * /my/script > /dev/null

If you still get messages after doing that, then the output is on stderr, thus it should be an error, which you should resolve.. If not, you can redirect stderr to /dev/null with..

2 * * * * /my/script > /dev/null 2> /dev/null

..although disregarding error messages is generally a bad idea! (How will you know when the cron job is broken?)

You could redirect a specific command's output from stderr to stdout using 2>&1 - for example:

command_which_prints_messages_to_stderr 2>&1 # redirect stderr to stdout

..then direct stdout to /dev/null in your cron job - that way you silence the loud command, without losing error messages

dbr

Posted 2009-07-18T02:07:40.903

Reputation: 4 987