0

I am trying to run a PHP script through a cronjob. I already did this hundred of times, but now it's not working and I cannot figure out why.

I created a script called update_db.php in /var/www/html/ When I run the script by hand:

php /var/www/html/update_db.php

everything works fine. When I put this into a cronjob, it does nothing. My cronjob:

* * * * * /usr/bin/php /var/www/html/update_db.php

I tried to put a bash script in front of it that calls the PHP script, but, again, it only works when calling by hand, not from a cron.

There are no errors in the syslog. Also no mail in /var/mail. I restarted cron already, but no effect.

I use ubuntu 14.04.

Can anyone help me?

msrd0
  • 7,816
  • 9
  • 47
  • 82
  • Check http://stackoverflow.com/tags/crontab/info and http://stackoverflow.com/a/17362250/ for some ideas about what can be happening. – fedorqui Sep 08 '14 at 16:05

2 Answers2

0

Is * * * * * php /var/www/html/update_db.php not working? You shouldn't need to use /usr/bin/php.

Also, check to make sure crons are running on your current system and that your files/directories have the appropriate permissions to be run by the cron.

Scott T Rogers
  • 515
  • 4
  • 17
  • Do you have any other crons currently running on your system? If so, are they running properly? – Scott T Rogers Sep 08 '14 at 16:26
  • Yes. I just tested another (test) database script and that works fine. Leaves me puzzled even more – Albert Kloosterman Sep 09 '14 at 06:55
  • It still sounds like a permissions issue to me. Have you changed the owner/group to the cron user and tried chmod to 777? Obviously you wouldn't want that in production, but if we can get that to work it's a place to start dialing back. – Scott T Rogers Oct 07 '14 at 14:21
0

CRON "should" be logging. Check the /var/log/cron, looking for your script errorrs or otherwise.

some implementations of cron need a full on restart - I have personanlly never had this issue, but I know fellow admins who have spent far too much time chasing fault, when a simple restart did the trick.

Coopz
  • 41
  • 3