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

I can run this command from CLI with not problem on the fedora box but not from a Cron:

/usr/bin/php /var/www/support_web/api/cron.php

This is the cron output:

Output from command /usr/bin/php /var/www/support_web/api/cron.php ..

77

File has execute permissions.

Crontab Log:

Jun 11 11:46:20 www crontab[23453]: (root) BEGIN EDIT (root)
Jun 11 11:46:21 www crontab[23453]: (root) REPLACE (root)
Jun 11 11:46:21 www crontab[23453]: (root) END EDIT (root)
Jun 11 11:47:01 www crond[2479]: (*system*) WRONG FILE OWNER (/etc/crontab)
Jun 11 11:47:01 www crond[2479]: (*system*) WRONG FILE OWNER (/etc/cron.d/smolt)
Jun 11 11:47:01 www crond[2479]: (root) RELOAD (cron/root)
share|improve this question
    
It sounds like the cron IS working - what are you expecting cron.php to do? –  Brent Jun 11 '09 at 15:07

4 Answers 4

up vote 1 down vote accepted

Are you running it from the CLI and from cron with the same user? If you run it from CLI as a normal user and from cron with root, root may be missing some environment variables your cron.php needs.

You could try running from root cron with something like:

su - userToRunAs -c "/usr/bin/php /var/www/support_web/api/cron.php"
share|improve this answer
    
su - root -c "/usr/bin/php /var/www/support_web/api/cron.php" This works fine in CLI. How can I check if I'm missing those environment variables? –  codex73 Jun 11 '09 at 15:25
    
This is the cron logs: Jun 11 11:46:20 www crontab[23453]: (root) BEGIN EDIT (root) Jun 11 11:46:21 www crontab[23453]: (root) REPLACE (root) Jun 11 11:46:21 www crontab[23453]: (root) END EDIT (root) –  codex73 Jun 11 '09 at 15:47
    
Jun 11 11:46:20 www crontab[23453]: (root) BEGIN EDIT (root) Jun 11 11:46:21 www crontab[23453]: (root) REPLACE (root) Jun 11 11:46:21 www crontab[23453]: (root) END EDIT (root) Jun 11 11:47:01 www crond[2479]: (system) WRONG FILE OWNER (/etc/crontab) Jun 11 11:47:01 www crond[2479]: (system) WRONG FILE OWNER (/etc/cron.d/smolt) Jun 11 11:47:01 www crond[2479]: (root) RELOAD (cron/root) –  codex73 Jun 11 '09 at 15:48

The cron files must have a user/group of root/root(/etc/cron* and /etc/cron.{daily,hourly,etc}/* must be owned by root, otherwise the scripts within will not fire off.

I don't know about personal crontabs under /var/spool/cron/$username. My personal experience, though, suggests that it's root/"user's group"

There are also some permissions requirements, but I don't know what those are. I do know, though, that 755 works.

share|improve this answer
    
This is currently set to Apache Apache: I have changed it to root:root /etc/cron.{daily,hourly,etc}/* –  codex73 Jun 11 '09 at 16:58

It's hard to say exactly, but it might be an environment variable that you have set in your interactive shell, but that isn't being set by cron. Put some print statements in cron.php that print out any environment variables that depends on, so you can see if it's properly set.

If that fails, add more print statements to see what's going on.

share|improve this answer

If the script for example lies in a directory such as cron.daily where files are executed automatically, some implementations of cron always run them with sh regardless of the shebang. Try to create simple sh-script that simply calls /usr/bin/php /var/www/support_web/api/cron.php.

share|improve this answer
    
Output from command /var/www/support_web/api/fetch.sh .. 77 –  codex73 Jun 11 '09 at 15:37

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.