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?
Best Answer
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:
to edit the crontab. Then add the following line:
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: