Search code examples
phpcroncron-task

crontab jobs not running


My cronjob never runs. I installed crontab using:

sudo apt-get update
sudo apt-get install cron

I then ran crontab -e and added this to the bottom:

* * * * * /usr/bin/php /var/app/monitor.php > /dev/null 2>&1

However, my script never runs. My script is:

<?php
  file_put_contents('/var/testlog.txt', "EVERYTHING ONLINE\n", FILE_APPEND);
?>

When I just run /usr/bin/php /var/app/monitor.php myself in my terminal it adds to testlog.txt however after each minute when I check testlog.txt I do not see a new line from crontab running my script.


Solution

  • For the command to run, the line must end in a new line (thus the file ends in a blank line). If it does not, it will ignore the line. That's a classic gotcha, and will cause the command to not run.