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 :

MAILTO=my@email.com

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=<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 is the name of the server.

UPDATE :

So in fact if I put the MAILTO=my@email.com 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

benjisail
  • 1,321
  • 5
  • 16
  • 32

3 Answers3

11

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 : MAILTO=my@email.com and not in /etc/crontab
benjisail
  • 1,321
  • 5
  • 16
  • 32
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.

jcomeau_ictx
  • 252
  • 4
  • 13
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
hamx0r
  • 151
  • 1
  • 7