Jobs in /etc/cron.d are not working on ubuntu

Viewed 9885

When I run php /var/www/html/devices/ac1/cron_on.php in the terminal it works normally. But nothing happens when I add it in the /etc/cron.d directory.

The cron job 49 11 * * * root php /var/www/html/devices/ac1/cron_on.php

I also tried 49 11 * * * root /usr/bin/php /var/www/html/devices/ac1/cron_on.php

And tried without root

1 Answers

To find the problem and make it work consider the following

  • Make sure the script in /etc/cron.d/ is owned by root:root (chmod root:root /etc/cron.d/<script>)
  • Make sure the script ends with a newline
  • If the script seem to not work try with a simples one e.g. * * * * * root echo test >> /tmp/cron_temp and monitor /tmp/cron_temp
  • service cron status will provide hints of how well the line executed
  • If the lines executed seems to be the culprit try running it as the user in the cron file sudo -u username <command-to-be-run>
Related