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 have a cron job scheduled to run under the root user, but it is silently failing.

The command calls a php script which among other things runs mysqldump via exec, this dump is not being created. There are no error messages in the apache log but other cron jobs are running ok. I'm not receiving any email errors (although despite having setup MAILTO I don't ever get emails even when removing > /dev/null)

When I run the same command directly via terminal everything runs ok, so I'm at a loss as to what's going wrong!

Update: I've add a database insert to the php script to try and figure out what's going on. This isn't working either but there are no entries in the apache log. As the script is being run via the terminal not as a webserver would error messages be logged elsewhere?

I've also tried changing the cron command to curl to the php script rather than run it directly but this isn't working either...

share|improve this question
    
Which distro and what is the file name. By default some crontab demons ignore some file extensions. For example on ubuntu .sh files in /etc/cron.*/ are ignored. –  golja Feb 5 '13 at 12:18
    
Distro is Ubuntu 11.10 (Oneiric Oncelot) –  blask Feb 5 '13 at 12:23

1 Answer 1

up vote 1 down vote accepted

PHP script might be run in different environment when cronjob compare to normal shell, i.e. the PATH variable might be different. In your crontab, do you specify the full path /usr/local/bin/script.php rather than script.php

share|improve this answer
    
At the beginning of the script I define a constant with the value of dirname(FILE) I then prepend all file reads and writes with this value to ensure I have the full path –  blask Feb 5 '13 at 12:24
    
@blask can you please paste your entry in from crontab. –  Wawrzek Feb 5 '13 at 13:53
    
As I was pasting in the cron, I realised the mistake. The path to the php file was incorrect. Thanks –  blask Feb 5 '13 at 14:04

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.