0
votes

I have setup a cron job thusly:

*/15 * * * * root /usr/bin/php5.6 /var/www/example.com/cr.php

(Yes, root is owner for now - I'll fix that later)

I have also tried with -q after .../php5.6

but it doesn't seem to be working, even though syslog shows it executes every 15 minutes - for example:

Dec 20 17:45:01 e2e-53-27 CRON[2601]: (root) CMD (root /usr/bin/php5.6 -q /var/www/example.com/cr.php)

If I execute the part after the username 'root' at the bash prompt it does work.

This is apache2 running on Debian. I don't know if this makes any difference but the PHP file is using curl to call an external API that sends an SMS.

1
can you run that on the command line... that's the first step. - ArtisticPhoenix
Yes, as I mentioned, I tried it at the bash prompt (= command line) and it works. - Chiwda
Add ` > /var/www/example.com/cr.log 2> /var/www/example.com/cr.error.log` to see if there is any errors. Also I suggest adding something simple first to file: echo date('Y-m-d H:i:s') - Justinas
Run the script as the same user in the same kind of condition, there may be environment variables set or not set that influence the behavior. - deceze
@Justinas your logging trick helped. Apparently it could not understand what "root" was. The erro log said something iike root not found. I thought providing a username was required?! - Chiwda

1 Answers

0
votes

You should use this format in cron file to make it work:

*/15 * * * * /usr/bin/php5.6 /var/www/example.com/cr.php

And the best way is to put this in script and add as first line in the script command:

. /root/.bash_profile

to make the environment as it is in command line