EC2实例发送每个成功或失败的cron作业的邮件 – 如何停止?

我们每天从cron deamon到[email protected]收到数百封邮件。 我怎样才能阻止呢? 这些邮件是指我们自定义的自定义cron作业 – 以及由AWS设置的其他作业。

邮件主题如下所示:

Cron <www-data@ip-172-12-34-56> [ -x /usr/share/awstats/tools/update.sh ] && /usr/share/awstats/tools/date.sh 

我读这是默认的行为,但我找不到方法来closures它。

crontab -lsudo crontab -l都不包含MAILTO指令或除正常的cron作业定时之外的任何东西。


 > cat vim /etc/crontab cat: vim: No such file or directory # /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 # mh 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 ) 

你有几个select。

您可以在crontab的开头设置一个MAILTO="*address*"variables来指定除root @以外的电子邮件地址,或者将其发送给一个不存在的电子邮件帐户。

你可以使用输出redirect,所以你可以通过添加>/dev/null 2>&1到你的cron作业的最后,把所有东西都发送到/ dev / null。

或者,您可以使用输出redirect的某种组合,只将错误发送到电子邮件或日志文件等。

http://wiki.bash-hackers.org/syntax/redirect有更多关于如何使用redirect的例子&#x3002;