I have a crontab (root) that runs a script and output is set to > /dev/null but I always get the emails whenever it runs. I only want to receive error emails.
# Rackspace driveclient update (12pm MST)
0 12 * * * /root/scripts/driveclient-update > /dev/null
The only way I can get it to turn off is to use > /dev/null 2>&1 but then I won't get error emails. This is happening on three different CentOS servers, two are 6.3 and one is 6.4.
NOTE: I have read over and over that > /dev/null is supposed to send stdout there and prevent the email if there is nothing but stdout from the script, so at works for at least some people; I cannot figure out why it is not working on these servers.
Here's an example of where > /dev/null is supposed to work:
Using the MAILTO
variable
The
MAILTO
variable allows you to set the email address that the notification emails from Cron are sent to. You can suppress all emails from your Cron jobs by setting this to an empty string like so:$ crontab -e
Now on the top of the file, add:
MAILTO=""
Then save and close the file.
Sending output to /dev/null
The
/dev/null
location in Linux is a "black hole" for data: any output sent here is gone, which makes it a great candidate for suppressing output from Cron jobs.To suppress all output (STDOUT and STDERR) from your Cron job, append
> /dev/null 2>&1
to the end of your job:$ crontab -e
Example:
*/30 * * * * command > /dev/null 2>&1
The number 2 represents the STDERR (standard error) stream, while 1 is the STDOUT (standard out) stream.
If you want to receive emails about errors only but not successes, append > /dev/null to your job to suppress output from STDOUT only:
*/30 * * * * command > /dev/null
Originally from alphadevx.com - Suppressing Cron Job Email Notifications (link is now dead)
>/var/log/mycron.log 2>/var/log/mycron.err
and see where that gets us. :)