0

When I build my server image, I write the following to a temporary file;

* * * * * php /var/www/artisan schedule:run

and then load it with

crontab < /tmp/cron

After deployment of the image, I run cron -f and I can see that the process is indeed running, but the cronjob is not being initiated.

If I run crontab -e, add a space, save it, run crontab -e again and remove the space, the cronjob working just fine without reload of cron.

I've tried reloading the cron on build with /etc/init.d/cron reload, but this does not solve the issue.

2
  • 1
    Does the file get created/updated in /var/spool/cron/crontabs? If so, check that the file ends in a newline; crontab entries aren't loaded if they don't end with a newline. Apr 11 '17 at 13:37
  • Yes, it is loaded and ends with a line break
    – Hedam
    Apr 11 '17 at 14:38
0

crontab needs to be notified. You can do something like this to (carefully!) append through the commandline or with a script:

(crontab -l 2>/dev/null; echo "* * * * * php /var/www/artisan schedule:run") | crontab -

The 2>/dev/null; suppresses crontab's message when a user has an empty crontab.

3
  • That's basically what I already do, which does not work.
    – Hedam
    Apr 11 '17 at 14:38
  • Sorry but no, that is not what you basically already do. Please look again at the example command I posted for you. It pipes through to crontab - so that crontab will be notified. Nothing in your first example, where you append, notifies crontab. In your second example, you invoke crontab -e, which notifies crontab. You need to notify crontab for it to pick up your job. Apr 11 '17 at 16:49
  • crontab < /tmp/cron notifies crontab
    – Hedam
    Apr 12 '17 at 9:16

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