4

Here's my situation:

I'm trying to run a php script via cron, and I've got a crontab (/etc/crontab) that looks like this:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/var/www:
MAILTO=<myemailaddress>

m h dom mon dow user  command

*  *    * * *   root    /usr/bin/php /var/www/testing.php

And when I run the command /usr/bin/php /var/www/testing.php from bash/sh, everything is dandy. It's just a basic php script that writes some gibberish to a file. However, my cronjob is not executing. I've used sudo service cron restart several times but all to no avail. Am I missing something obvious here?

Thanks, and cheers!

Solution

My own fault! The php script I was running was writing to a file that was not properly accessed - e.g., lacking full file paths. Thanks for the help all!

7
  • Do you have a blank line right after your rule in the cronjob file?
    – zerkms
    Apr 26, 2011 at 0:06
  • My actual cron table begins and ends with '#', where the closing pound sign is on its own line after my code snippet right there. That is the EOF.
    – Paul
    Apr 26, 2011 at 0:26
  • edit:: Guess last comment disappeared, as for the OS it's just Ubuntu. This is the master crontab, not an individual user's -- that is, it lives in /etc/crontab. The user-specific crontabs do not have a user column.
    – Paul
    Apr 26, 2011 at 0:34
  • Yes -- I just did * * * * * root echo hi >> /tmpnonsense and it worked. Every minute it appended hi.
    – Paul
    Apr 26, 2011 at 0:51
  • 5
    Can you answer your own question in a way that would help others? If you do, you can select yours as the correct answer. It may seem strange, but it is the preferred way of dealing with situations like this.
    – user1228
    Jun 15, 2011 at 18:39

1 Answer 1

0

Create a shell script and put the PHP command in there. Make it executeabl and put it into the crontab.

You can then better track and change the command as well as setting up the environment (vars, paths) for the php script more easily.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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