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
So to answer my question :
yum install mailx
yum install sendmail
MAILTO
line into the crontab usingcrontab -e
:[email protected]
and not in/etc/crontab
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.
My
/var/log/maillog
was showing thatcrontab
(withMAILTO=root
) was trying to send email to bothroot
androot@my_fqdn
(wheremy_fqdn
is like server.something.com). Per the log, sending toroot
was successful androot@my_fqdn
failed, yet I found not message in/var/mail/root
. Here's the relevant/var/log/maillog
snippet:However, per this tip, mail now shows up in
/var/mail/root
. The problem was/etc/hosts
needed to have a line added somy_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
(noticestat=Local configuration error
below in/var/log/maillog
snippet).