8

I am trying to debug an issue with cron not sending mail on a Centos 6 box that I did not configure. How can I determine which mailer cron is using to send mail? The crontab man page has this to say, in part:

In addition to LOGNAME, HOME, and SHELL, cron(8) will look at MAILTO if it has any reason to send mail as a result of running commands in "this" crontab. If MAILTO is defined (and non-empty), mail is sent to the user so named. If MAILTO is defined but empty (MAILTO=""), no mail will be sent. Otherwise mail is sent to the owner of the crontab. This option is useful if you decide on /bin/mail instead of /usr/lib/sendmail as your mailer when you install cron -- /bin/mail doesn´t do aliasing, and UUCP usually doesn´t read its mail.

The part with asterisks is the part that has me wondering "Well, is it sendmail or mail?"

3

A quick Google shows me that /etc/sysconfig/crond is the file that defines what mailer is used by cron.

  • My Google-fu is apparently terrible because I spent a good amount of time looking for this. Thanks. – cbmanica Sep 29 '14 at 22:58
16

According to the man page for cron(8) (the daemon that actually sends the message):

   -m     This  option  allows you to specify a shell command string to use for 
          sending cron mail output instead of sendmail(8).  This command must 
          accept a fully formatted mail message (with headers) on stdin and send
          it as a mail message to the recipients specified in the mail headers.

That leads me to believe that it's using sendmail by default. Let's verify with strace:

Set up a cron job that'll generate email:

user@host1 ~:
$ crontab -e
crontab: installing new crontab
user@host1 ~:
$ crontab -l
MAILTO=example@example.com
*/5 * * * * echo "testing"

Now find the process ID for crond:

user@host1 ~:
$ ps auxww | grep crond
root      9684  0.0  0.0 117280  1296 ?        Ss   Jul22   0:17 crond
user     36344  0.0  0.0 103240   884 pts/2    S+   23:01   0:00 grep crond

Attach to the crond process with strace, looking for process related activity. As strace writes to stderr I've redirected it to stdout and grepped for 'mail':

root@host1 ~:
# strace -fp 9684 -s 1024 -e trace=process 2>&1 | grep mail
[pid 36204] execve("/usr/sbin/sendmail", ["/usr/sbin/sendmail", "-FCronDaemon", "-i", "-odi", "-oem", "-oi", "-t", "-f", "root"], [/* 16 vars */]) = 0
^C

Yep, it's sendmail.

  • 3
    On the system you tested. – mfinni Sep 30 '14 at 4:10
  • 2
    Right, which is CentOS as tagged on this question, in its default configuration. – yoonix Sep 30 '14 at 12:56
  • 1
    I know I'm banging a tired drum here, but it's a configurable parameter, and the question involved a system that the asker did not set up. The mailer could have been previously changed from the default, for the system in question. The asker knows the default. – mfinni Sep 30 '14 at 17:58
  • 3
    Right but in it's default configuration, there is nothing referencing mail in the config file (minus comments, the entire content is CRONDARGS=). The fact that it's configurable is why I included the steps to verify for one's self. – yoonix Sep 30 '14 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.