1

I'm having a strange problem here with crontab. I have set up the crontab correctly to run the cron job as follows:

[user@user ~]$ crontab -e
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
[email protected]
HOME=/

2 * * * * php usr/share/nginx/html/site/script.php

The script runs, I know this because the script is just a basic test that uses the mail() function to let me know it ran.

But I do not get the e-mail from crontab to let me know the script has ran. I should be getting an output e-mail to the MAILTO address above but I am not. I have even tried with quotes around the address.

There's nothing wrong with Sendmail because otherwise the script wouldn't be able to send an e-mail. There's nothing wrong with the e-mail address either because the mail() code in script.php sends to the same e-mail address.

Technically I could just send the e-mail output myself this way rather than rely on crontab but I know that's not the right way to do it.

Any idea where I am going wrong?

PS. This is a Centos 6.3 server.

1
  • 1
    Does your script produce any output to stdout and/or stderr? If not, then cron will not send an email. Apr 21, 2013 at 15:04

2 Answers 2

3

What you can do is to remove that MAILTO and then just use a root forwarder.

/root/.forward <- just place your email in there, nothing else. Assuming you are running the cron job as root. You can also do it via /etc/aliases, add the line: user: [email protected]

2
  • I put my e-mail in that file and removed the MAILTO and still didn't get an e-mail. Haven't tried the second thing you said yet though.
    – Xenor
    Apr 21, 2013 at 13:28
  • The second solution didn't work either.
    – Xenor
    Apr 21, 2013 at 13:36
0

I would check cron and mail log to see whether there is any error reported. Could that be also possible the email is landed in your junk mail folder or recipient mail server rejected the mail for invalid sender name or hostname etc.,?

4
  • There's nothing in the cron log, just a line saying the command was ran. It's not a junk folder issue either, been checking that and I've also tried directing the output to an e-mail address at a different provider. I did have to edit the mail config to bypass local e-mail check though as shown here serverfault.com/questions/65365/… because php mail(); wasn't working at all on my the server's own domain, I wonder if that broke it.
    – Xenor
    Apr 21, 2013 at 14:50
  • 2
    Please do a live tail of mail log when your cron runs and see what is happening. You should see where is sendmail relaying to. tail -f /var/log/maillog
    – antimatter
    Apr 21, 2013 at 15:12
  • 1
    I've no idea why but it started working around 5pm yesterday. I think I did reboot my server late afternoon so maybe that changed something. Or the MAILFROM parameter I added.
    – Xenor
    Apr 22, 2013 at 20:14
  • Checking the mail log (in my case /var/log/exim4/mainlog) allowed me to spot the problem which was that I had a stale root: myuser entry in /etc/aliases and the user myuser didn't exist anymore. Apr 6, 2020 at 2:59

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