如何停止 Cron 的电子邮件报告(每小时)

如何停止 Cron 的电子邮件报告(每小时)

我正在运行 Ubuntu 12.04,我已经使用我的 gmail 帐户配置了“ssmtp”,现在我每小时都会收到一封带有报告的电子邮件,这是一个例子:

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

更多信息:

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"

更多的...

$ sudo crontab -l -u root
no crontab for root

更多的...

$ 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 )
#

我已经评论了该行17 * * * * root cd / && run-parts --report /etc/cron.hourly,但电子邮件仍然到达。

答案1

只需添加以下内容/etc/crontab

MAILTO=""

要完全阻止 crontab 发送电子邮件,请编辑/etc/sysconfig/crond并添加此内容CRONDARGS='-m off'
保存并重新启动 crond。

答案2

当 cron 启动一个进程时,它会捕获到达 stdout 和 stderr 的任何输出,并将其通过电子邮件发送。为了防止这些电子邮件,您可以将 stdout 和 stderr 重定向到您监控的日志文件或 /dev/null(如果您不介意的话)。

17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly 2>&1 > /dev/null

相关内容