How to stop email report from Cron <root@machine> (hourly)
50,972
Solution 1
Just add below to /etc/crontab
MAILTO=""
to stop crontab from sending email totally edit /etc/sysconfig/crond
and add this CRONDARGS='-m off'
.
Save and restart crond.
Solution 2
When cron starts a process, it captures any output that reaches stdout and stderr, and sends that in an email. To prevent these emails, you can re-direct the stdout and stderr, either to a logfile that you monitor, or /dev/null, if you don't care.
17 * * * * root cd / && run-parts --report /etc/cron.hourly 2>&1 > /dev/null
Related videos on Youtube
Author by
user83162
Updated on September 18, 2022Comments
-
user83162 over 1 year
I'm running an Ubuntu 12.04, I've configured "ssmtp" with my gmail account and now I'm getting every hour an email with a report, this is an example:
From: root <[email protected]> Date: 2012/8/13 Subject: Cron <root@one> [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete To: root Failed loading /usr/lib/php5/20090626/xdebug.so: /usr/lib/php5/20090626/xdebug.so: cannot open shared object file: No such file or directory
Some more info:
$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=12.04 DISTRIB_CODENAME=precise DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"
More...
$ sudo crontab -l -u root no crontab for root
More...
$ nano /etc/crontab # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) #
I've commented the line
17 * * * * root cd / && run-parts --report /etc/cron.hourly
, but the email still arriving. -
user83162 over 11 yearsHi! Thanks for answer me so quickly! I've found this issue that I think is causing the problem: bugs.launchpad.net/ubuntu/+source/php5/+bug/876387 So, until the problem is resolved, I'm going to apply your solution! Thanks again! nonox
-
Sindhuja Ravula over 9 yearsI like this answer because it can disable mails for a specific job, rather than the MAILTO="" which would disable all cron mail.
-
ThorSummoner over 8 yearsIt appears this line has to be added to every crontab file wanted silenced, (atleast from my testing). also beware that user crons live elsewhere: serverfault.com/a/325344/210994
-
3kstc almost 8 years@ThorSummoner When mentioning "...every crontab file..." is that in the crontab itself, or in the script, underneath the shebang line?