Updated (and snipped) with more details below.
I've set up a cron script and I'm trying to debug why it's not running. [Snipped context testing, which is all ok; see revision 2 for details] The command itself, in case it helps, (arrows indicate line-wrapping for legibility) is:
/usr/bin/php -C /etc /path/to/process.php
↪ >>/path/to/stdout.log 2>>/path/to/stderr.log
[Snipped permissions testing, which is all ok; see below and revision 2 for details]
Checking crontab
(again, wrapped for legibility), I get:
[blackero@XXXXXXXXXXX to]$ sudo crontab -u cronuser -l
MAIL="blackero@localhost"
30 9 * * * cronuser /usr/bin/php -C /etc /path/to/process.php
↪ >>/path/to/stdout.log 2>>/path/to/stderr.log
20 18 7 * * cronuser /usr/bin/php -C /etc /path/to/process.php
↪ >>/path/to/stdout.log 2>>/path/to/stderr.log
22 18 7 * * cronuser echo "Test" > /path/to/test.txt
↪ 2> /path/to/error.txt
Update #1 at 2012-02-08 12:32 Z
[Snip: Having tried derobert's suggestion (revision 3)], I know that the cronuser
can run the script properly and can write to the two .log
files. (One of the first things the process.php
script does is download a file by FTP; it is successfully doing that too.) But, even after fixing the MAIL=""
line (both by removing it and by changing it to MAILTO="blackero@localhost"
), the cron task still doesn't run, nor does it send me any email.
A friend suggested that I retry the
9 12 8 * * cronuser /bin/echo "Test" > /var/www/eDialog/test.txt
↪ 2> /var/www/eDialog/error.txt
task, after passing the full path to /bin/echo
. Having just tried that, it also didn't work and also generated no email, so I'm at a loss.
Update #2 at 2012-02-08 19:15 Z
A very useful chat conversation with oHessling, it would seem that the problem is with pam
. For each time that cron
has tried to run my job, I have /var/log/cron
entries:
crond[29522]: Authentication service cannot retrieve authentication info
crond[29522]: CRON (cronuser) ERROR: failed to open PAM security session: Success
crond[29522]: CRON (cronuser) ERROR: cannot set security context
I fixed that by adding the following line to /etc/shadow
:
cronuser:*:15217:0:99999:7:::
As I found on a forum, if the user does not appear in /etc/shadow
, then pam
won't continue processing the security request. Adding *
as the second column means this user cannot log in with a password (as no hash is specified). Fixing that led to a different error in /var/log/cron
, so, double-checking my crontab
I noticed I had specified the username each time.
Correcting that means my crontab
now reads:
[blackero@XXXXXXXXXXX ~]$ sudo crontab -u cronuser -l
MAILTO="blackero@localhost"
30 9 * * * /usr/bin/php -C /etc /path/to/process.php
↪ >>/path/to/stdout.log 2>>/path/to/stderr.log
52 18 8 * * /usr/bin/php -C /etc /path/to/process.php
↪ >>/path/to/stdout.log 2>>/path/to/stderr.log
9 12 8 * * /bin/echo "Test" > /path/to/test.txt
↪ 2> /path/to/error.txt
but now /var/log/cron
shows me:
Feb 8 18:52:01 XXXXXXXXXXX crond[16279]: (cronuser) CMD (/usr/bin/php -C /etc
↪ /path/to/process.php >>/path/to/stdout.log 2>>/path/to/stderr.log)
and nothing comes into the stdout.log
or the stderr.log
. No mail was sent to me and none of the other files in /var/log/
has any entry in the right timeframe, and I'm running out of ideas as to where to look to see what's going wrong
pam
issue, it was really obvious from/var/log/cron
that this was the case). But I still haven't fixed. it. Update coming within a minute or two. – Owen Blacker Feb 08 '12 at 19:13flush
/ob_flush
); (b) start putting<?php echo "about to frob" ?>
lines in the script, and see how far it gets; (c) make sure PHP is set to spew errors to stderr—not just some error log (that it may not even have permission to under that user) – derobert Feb 09 '12 at 16:27echo hello | mail -s 'test message' your-user
and see if that mail goes somewhere useful (just to make sure local mail is working on the box). – derobert Feb 09 '12 at 16:30cronuser
earlier in the week (and was sending output to both stdout and stderr before I tweaked it), but I'll try testingmail
when I get to the office tomorrow; thanks :o) – Owen Blacker Feb 09 '12 at 23:48sudo su -s /bin/sh cronuser
andecho hello | mail -s 'test message' blackero
, I do end up with a message in my mailbox. The two filesstdout.log
andstderr.log
already exist (from having run the script in a minimal shell, per your earlier suggestion), so I know it's not the PHP script that's the problem; it's something about the configuration ofcron
(presumably). That test also confirmed that the PHP output does go tostdout
andstderr
, rather than some other log. – Owen Blacker Feb 10 '12 at 13:58