Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a cronjob in /etc/cron.d/mycron that looks like this:

0 3 * * * apache php /path/to/my/script.php

In the same file there are other cronjobs begin run as root and other users (which work), but for some reason this job running as apache isn't running and isn't reporting anything in /var/log/messages or sending anything to the MAILTO address in the cron file. When I su apache and run the cronjob's command, it works fine, but cron doesn't like it.

This is a long running problem for me and so far I have gathered the following possibilities:

  • The apache user doesn't have a home directory (the other cron users do), and crond doesn't like this.
  • There's some PAM or /etc/security/access.conf setting blocking apache using crond, although /etc/security/access.conf is completely commented out.
  • SELinux - this is usually the culprit when a problem seems really weird.

Any ideas or experience with this problem and what the solution might be?

Thanks

share|improve this question
1  
Do you see anything in /var/log/cron? –  larsks Aug 15 '12 at 16:16
    
What are the ownership and permissions on the file ? –  Iain Aug 15 '12 at 16:25
    
Is the cron daemon running? –  Garrett Aug 15 '12 at 16:28
    
$ service crond status ... crond (pid 28490) is running.... Also, the file perms are 664, but since I can log in as apache myself and run the command manually this cannot be the issue. –  Tom Aug 16 '12 at 19:45
    
There's no mention of the cronjob in /var/log/cron –  Tom Aug 16 '12 at 19:52
add comment

2 Answers

up vote 1 down vote accepted
  • Try using full path for php in cron config: /usr/bin/php
  • Check apache home directory: grep apache /etc/passwd As far as I know, user should always have home directory. It may reside not in /home.
  • Check syslog messages about security events. If this is PAM, you'll see something
  • Try disabling SELinux
share|improve this answer
1  
Found it. (CRON) ERROR chdir failed (/home/apache): No such file or directory. Cron users need a home dir. –  Tom Aug 16 '12 at 19:58
add comment

cron by default runs with a very limited PATH; do you need to put in the full path to the php binary?

share|improve this answer
    
For simplicity I removed the full path when I posted on here - but yes, the actual cronjob is 0 3 * * * apache /usr/local/bin/php -c /etc/php.ini /path/to/my/script.php –  Tom Aug 16 '12 at 19:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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