MAILTO不适用于CRON。我怎样才能解决这个问题?


8

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

MAILTO=my@email.com

我已经使用安装了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。
  • 我开始了sendmail。
  • 因此,现在可以从命令行发送电子邮件了!

我在邮件日志中收到此错误:

Feb 23 16:06:01 internal sendmail[7210]: o1NG61cd007210: from=root, size=425, class=0, nrcpts=1, msgid=<201002231606.o1NG61cd007210@internal.fff.com>, relay=root@localhost
Feb 23 16:06:01 internal sendmail[7211]: o1NG61hT007211: from=<root@internal.fff.com>, size=732, class=0, nrcpts=1, msgid=<201002231606.o1NG61cd007210@internal.fff.com>, 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=<root@internal.fff.com>, ctladdr=<root@internal.fff.com> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30972, dsn=2.0.0, stat=Sent

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

更新:

因此,实际上,如果我将MAILTO=my@email.comcrontab(使用crontab -e)作为第一行(使用),它将起作用。

为什么通过设置MAILTOin 不起作用/etc/crontab

谢谢


邮件服务器中的日志怎么说?mailx如何配置为发送邮件?
Bill Weiss,2010年

另外,请尝试使用mailx手动发送邮件,然后在邮件服务器上比较生成的日志。
克里斯·S

/ var / log / maillog为空我尚未配置mailx
benjisail 2010年

您可以从命令行发送邮件吗?
暂停,直到另行通知。

您能先回答这里提到的建议吗?请尝试从命令行发送邮件。
DaDaDom,2010年

Answers:



0

您可以通过安装nullmailer而不是sendmail(或exim4或postfix等)来简化此操作。

如果它不起作用(因为我的不起作用),并且您要发送到gmail之类的网络邮件服务,请确保未在其上放置任何过滤器。实际上,我对cron中的任何内容都设置了过滤器,以绕过收件箱。这就是为什么我从我的Cron工作中什​​么都看不到的原因。


0

我的/var/log/maillog展示是crontab(与MAILTO=root)试图同时向root和 发送电子邮件root@my_fqdnmy_fqdn类似于server.something.com)。根据日志,发送到root成功root@my_fqdn失败,但我在中找不到消息/var/mail/root。以下是相关/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来解决该问题,以便将其作为域解决(请注意最后的点): 127.0.0.1 my_fqdn.

注意:现在,这种方法的工作方式是仍然无法正确接收消息,但是会以将其放回原处的方式弹回/var/mail/root(请注意stat=Local configuration error以下/var/log/maillog摘录中的片段)。

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
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.