Home » Questions » Computers [ Ask a new question ]

Stop cron from emailing me

Stop cron from emailing me

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

Asked by: Guest | Views: 266
Total answers/comments: 2
Guest [Entry]

"By setting the environment variable ""MAILTO"" as """"

Somethig like:

SHELL=/bin/bash
MAILTO=

01 * * * * /your/path/to/script/here.sh"
Guest [Entry]

"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"