1

Okay, I have a php script that has to be executed each 15 minutes, but that does not work. My other scripts just get executed just fine, and I can execute it via the command line.

# m h  dom mon dow   command
30 2 * * 1 /usr/bin/letsencrypt renew >> /var/log/le-renew.log
* 10 * * 0 php /var/www/html/slack/huiswerk_reminder/runner.php
* 17 * * 1 php /var/www/html/slack/huiswerk_reminder/runner.php
* 17 * * 2 php /var/www/html/slack/huiswerk_reminder/runner.php
* 14 * * 3 php /var/www/html/slack/huiswerk_reminder/runner.php
* 16 * * 4 php /var/www/html/slack/huiswerk_reminder/runner.php
*/15 * * * *  php /var/www/html/slack/cijfercheck/cijfercheck.php

Only */15 * * * * php /var/www/html/slack/cijfercheck/cijfercheck.php wont get executed. What am I doing wrong??

Steps I have taken to try fix it:

Change */15 to 0,15,30,45

And looked at all these questions:
https://stackoverflow.com/questions/32393740/cronjob-not-executing-php
https://stackoverflow.com/questions/5784573/cronjobs-not-executing-php-scripts-no-mailto-warnings-received https://askubuntu.com/questions/23009/reasons-why-crontab-does-not-work https://askubuntu.com/questions/93313/cron-job-not-running Why is my crontab not working, and how can I troubleshoot it?

It all does not work, and the weird thing is, the others work just fine, no problem at all...
So what am I doing wrong?

Luuk Wuijster
  • 139
  • 1
  • 6
  • 1
    How do you know it isn't working? Do you have errors in your system logs? What are the specific errors? – Zoredache Dec 10 '16 at 00:26
  • The first thing the php script does is loggin that it started. And when I look in those logs I dont see anything. – Luuk Wuijster Dec 10 '16 at 00:27
  • Okay, it does seem to be running the php script, but its not logging for some weird reason, because it works fine when I run from the browser or the command line. – Luuk Wuijster Dec 10 '16 at 00:32
  • If it is running and failing in some way, then you need to debug permissions, paths and so on. Something about the environment of that user's cron is different from your command line environment. – Zoredache Dec 10 '16 at 00:34
  • Yes, but the other php scripts run just fine on that user. – Luuk Wuijster Dec 10 '16 at 00:38

1 Answers1

1

You need a blank line at the end of your crontab, or it won't work. Also try adding #!/bin/bash before your scripts to ensure they run in BASH, rather than some other shell.

If that doesn't work, then you can try offloading to a .sh script:

*/15 * * * * $HOME/sched.sh >> $HOME/log_sched 2>>$HOME/error_sched

then you fill it out as a BASH script:

#!/bin/bash

php5 /var/www/html/slack/cijfercheck/cijfercheck.php &&

echo FINISHED AT $(date +"%T")
Sabine
  • 11
  • 2
  • Yes, I know. And I tried that, but it just does not work. I'm thinking it has something to do with permissions, but not sure. And I still do not understand why I am able to run other php scripts and not this one... :/ – Luuk Wuijster Dec 10 '16 at 00:53
  • If you add 2>>/path_to_error_log to your crontab, if should give you an error message of some kind in your log. Which crontab are you running? Each user has a different one, so if you need root access, make sure you edit it using sudo crontab -e. crontab -e works for the current user, and you may lack permissions on that account. – Sabine Dec 10 '16 at 01:05
  • Okay, I added that and I dont see any error log, and I now know its running, but its just lacking of permissions to write to the log. What do I have to give the permissions? I just set all perms to 777 but it still does not write to the log file... – Luuk Wuijster Dec 10 '16 at 13:37