11

I have setup cronjob for the root user. However when the cron fail I should receive an email from the cronjob because I have set MAILTO like this in /etc/crontab :

[email protected]

I have installed mailx using

yum install mailx

But when I look at the cron log I get these lines :

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 )

How can I fix this?

UPDATE :

  • I installed mailx and sendmail using yum.
  • I started sendmail.
  • So now sending an email is working from the command line!

I get this error in the 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 is the name of the server.

UPDATE :

So in fact if I put the [email protected] as the first line of my crontab (using crontab -e) it is working.

Why is it not working by setting the MAILTO in /etc/crontab ?

Thanks

6
  • What do the logs from your mail server say? How is mailx configured to send mail?
    – Bill Weiss
    Feb 23, 2010 at 14:36
  • Also, try sending something manually using mailx and compare the resulting logs on the mail server.
    – Chris S
    Feb 23, 2010 at 14:50
  • /var/log/maillog is empty I haven't configured mailx
    – benjisail
    Feb 23, 2010 at 14:50
  • Can you send mail from the command line? Feb 23, 2010 at 14:50
  • Could you answer the recommendations mentioned here first, please? Try sending a mail from the command line, please.
    – DaDaDom
    Feb 23, 2010 at 15:22

3 Answers 3

12

So to answer my question :

  • Install mailx yum install mailx
  • Install sendmail yum install sendmail
  • Start sendmail
  • Put the MAILTO line into the crontab using crontab -e : [email protected] and not in /etc/crontab
2
0

you can simplify this by installing nullmailer instead of sendmail (or exim4, or postfix, etc.).

if it's not working, as mine was not, and you're sending to a webmail service such as gmail: make sure you didn't put any filters on it. I in fact had a filter on anything from cron, to bypass the inbox. that's why I wasn't seeing anything from my cron jobs.

0

My /var/log/maillog was showing that crontab (with MAILTO=root) was trying to send email to both root and root@my_fqdn (where my_fqdn is like server.something.com). Per the log, sending to root was successful and root@my_fqdn failed, yet I found not message in /var/mail/root. Here's the relevant /var/log/maillog snippet:

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.

However, per this tip, mail now shows up in /var/mail/root. The problem was /etc/hosts needed to have a line added so my_fqdn would resolve as a domain (notice the dot at the end): 127.0.0.1 my_fqdn.

Note: The way this is working now is that the message is still failing to be received properly, but is bouncing back in a way that lands it in /var/mail/root (notice stat=Local configuration error below in /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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .