Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Server is Debian 6.0. In /etc/aliases I have;

root: me@mydomain.com

This is so that root emails get sent directly to me. Today, a monthly script I have placed into /etc/cron.monthly has emailed me it's output. It a fairly simply script which looks like this;

#!/bin/bash
cd /a/directory
rm -rf ./*
wget http://www.site.com/fresh-copy.zip
unzip fresh-copy.zip
rm fresh-copy.zip

The email I have received is below;

**Subject**: Cron <root@myserver> test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
**From**: root@my.server.com
**Body**:

    /etc/cron.monthly/speedtest:
--2013-03-01 06:52:01--  http://www.site.com/fresh-copy.zip
Resolving www.site.com... 11.22.33.44
Connecting to www.site.com|11.22.33.44|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 99763924 (95M) [application/zip]
Saving to: `fresh-copy.zip'

     0K .......... .......... .......... .......... ..........  0% 11.7M 8s
    50K .......... .......... .......... .......... ..........  0% 11.3M 8s
   100K .......... .......... .......... .......... ..........  0% 11.4M 8s
        *CUT OUT FOR BREVITY*
 97350K .......... .......... .......... .......... .......... 99% 16.9M 0s
 97400K .......... .......... .....                           100% 11.6M=9.7s

2013-03-01 06:52:11 (9.78 MB/s) - `fresh-copy.zip' saved [99763924/99763924]

Archive:  fresh-copy.zip
  inflating: file1.ext
  inflating: file2.ext
  inflating: file3.ext
  inflating: file4.ext
  inflating: file5.ext

The only output in this email is from the wget and unzip command. I can edit the script and place > /dev/null on the end on those two lines, but is that really the best way to do this? If I add more commands to the script that produce output, I will always have to add on > /dev/null to each line. Is there a way I can disable email notification of output from this cron script?

share|improve this question
add comment

4 Answers

up vote 2 down vote accepted

An easier method is to instead of adding the script to the cron.monthly directory, you add it to an old-fashioned crontab, where you can specify on the crontab line that you want output to go to /dev/null. Like this:

crontab -e

to edit the crontab. Then add the following line:

@monthly /path/to/script > /dev/null

This will mean that STDOUT gets redirected to /dev/null, but STDERR will still end up in an email. If you don't want to get mails on error either, the line should look like this:

@monthly /path/to/script > /dev/null 2>&1
share|improve this answer
    
So simple, thank you! :D –  jwbensley Mar 4 '13 at 10:04
add comment

I would recommend that you keep using > /dev/null in your script (or use the -q option for wget and unzip). This way, if one of the commands throws errors, these will still be emailed to you, but normal output will be suppressed.

share|improve this answer
add comment

I have been using cronic for a while, it has never failed me.

Essentially it's a wrapper script for your cron, which will only send you email if there is an error return code, or if there is something in stderr. This way you don't get spammed every time the cron runs, but still get notified when something is wrong.

To use it, download the cronic script and change your cron command from (for example)

* * * * * awesome_command

to

* * * * * /path/to/cronic awesome_command
share|improve this answer
add comment

If you want to "mute" only this script you can put /dev/null 2>&1 at the end of the line calling your file in the crontab file. With this method you can't put your script in the monthly folder, you need to edit the crontab file with :

contab -e

Or you can edit cron config and remove your mail from it. Every thing is explained here.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.