MAILTO不适用于CRON。 我该如何解决这个问题?

我已经为root用户设置了cronjob。 但是,当cron失败,我应该收到来自cronjob的电子邮件,因为我已经在/ etc / crontab中设置了MAILTO:

[email protected] 

我已经安装了mailx使用

 yum install mailx 

但是当我看到cron日志时,我得到这些行:

 Feb 23 14:13:01 internal crond[6858]: (root) CMD (/var/www/vded/build/bin/sync.sh) Feb 23 14:13:01 internal crond[6857]: (root) MAIL (mailed 79 bytes of output but got status 0x0001 ) 

我该如何解决这个问题?

更新:

  • 我用yum安装了mailx和sendmail。
  • 我开始发送邮件。
  • 所以现在发送电子邮件正在从命令行工作!

我在maillog中得到这个错误:

 Feb 23 16:06:01 internal sendmail[7210]: o1NG61cd007210: from=root, size=425, class=0, nrcpts=1, msgid=<[email protected]>, relay=root@localhost Feb 23 16:06:01 internal sendmail[7211]: o1NG61hT007211: from=<[email protected]>, size=732, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1] Feb 23 16:06:01 internal sendmail[7210]: o1NG61cd007210: to=root, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30425, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (o1NG61hT007211 Message accepted for delivery) Feb 23 16:06:01 internal sendmail[7212]: o1NG61hT007211: to=<[email protected]>, ctladdr=<[email protected]> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30972, dsn=2.0.0, stat=Sent 

internal.fff.com是服务器的名称。

更新:

所以实际上,如果我把[email protected]作为我的crontab的第一行(使用crontab -e ),它正在工作。

为什么在/etc/crontab设置MAILTO不起作用?

谢谢

所以要回答我的问题:

  • 安装mailx yum install mailx
  • 安装sendmail yum install sendmail
  • 启动sendmail
  • 使用crontab -e[email protected]MAILTO行放入crontab中,而不是在/etc/crontab

你可以通过安装nullmailer而不是sendmail(或exim4或postfix等)来简化这个过程。

如果它不工作,因为我没有工作,并且你正在发送到一个webmail服务,如gmail:确保你没有任何filter。 我实际上有一个filter从cron的任何东西,绕过收件箱。 这就是为什么我没有看到我的任何工作。

我的/var/log/maillog显示crontab (使用MAILTO=root )试图发送邮件给rootroot@my_fqdn (其中my_fqdn就像server.something.com)。 根据日志,发送到root是成功的,并且root@my_fqdn失败,但是在/var/mail/root没有find消息。 以下是相关的/var/log/maillog代码片段:

 Aug 16 17:49:02 ip-10-64-21-125 sendmail[22211]: v7GHn2Tr022211: from=root, size=742, class=0, nrcpts=1, msgid=<201708161749.v7GHn2Tr022211@my_fqdn>, relay=root@localhost Aug 16 17:49:02 ip-10-64-21-125 sendmail[22212]: v7GHn2Ws022212: from=<root@my_fqdn>, size=1061, class=0, nrcpts=1, msgid=<201708161749.v7GHn2Tr022211@my_fqdn>, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1] Aug 16 17:49:02 ip-10-64-21-125 sendmail[22211]: v7GHn2Tr022211: to=root, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30742, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (v7GHn2Ws022212 Message accepted for delivery) Aug 16 17:49:02 ip-10-64-21-125 sendmail[22214]: v7GHn2Ws022212: to=<root@my_fqdn>, delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=121061, relay=my_fqdn. [10.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by my_fqdn. 

但是, 根据这个提示 ,邮件现在显示在/var/mail/root 。 问题是/etc/hosts需要添加一行,所以my_fqdn作为域parsing(注意最后一点): 127.0.0.1 my_fqdn.

注意:现在这个工作的方式是这个消息仍然没有被正确接收,但是以/var/mail/root的方式反弹回来(注意stat=Local configuration error/var/log/maillog snippet)。

 Aug 16 17:50:04 ip-10-64-21-125 sendmail[22223]: v7GHo4ZJ022223: from=root, size=742, class=0, nrcpts=1, msgid=<201708161750.v7GHo4ZJ022223@my_fqdn>, relay=root@localhost Aug 16 17:50:04 ip-10-64-21-125 sendmail[22224]: v7GHo4MT022224: from=<root@my_fqdn>, size=1061, class=0, nrcpts=1, msgid=<201708161750.v7GHo4ZJ022223@my_fqdn>, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1] Aug 16 17:50:04 ip-10-64-21-125 sendmail[22223]: v7GHo4ZJ022223: to=root, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30742, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (v7GHo4MT022224 Message accepted for delivery) Aug 16 17:50:04 ip-10-64-21-125 sendmail[22226]: v7GHo4MT022224: SYSERR(root): my_fqdn. config error: mail loops back to me (MX problem?) Aug 16 17:50:04 ip-10-64-21-125 sendmail[22226]: v7GHo4MT022224: to=<root@my_fqdn>, delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=121061, relay=my_fqdn. [127.0.0.1], dsn=5.3.5, stat=Local configuration error Aug 16 17:50:04 ip-10-64-21-125 sendmail[22226]: v7GHo4MT022224: v7GHo4MT022226: DSN: Local configuration error Aug 16 17:50:04 ip-10-64-21-125 sendmail[22227]: v7GHo4Ml022227: localhost [127.0.0.1] did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA Aug 16 17:50:04 ip-10-64-21-125 sendmail[22226]: v7GHo4MT022226: to=root, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=62294, dsn=2.0.0, stat=Sent Aug 16 17:50:04 ip-10-64-21-125 sendmail[22226]: v7GHo4MT022226: to=<root@my_fqdn>, delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=62294, relay=my_fqdn., dsn=5.3.5, stat=Local configuration error Aug 16 17:50:04 ip-10-64-21-125 sendmail[22226]: v7GHo4MT022226: v7GHo4MU022226: return to sender: Local configuration error Aug 16 17:50:04 ip-10-64-21-125 sendmail[22226]: v7GHo4MU022226: to=root, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=33318, dsn=2.0.0, stat=Sent