0

I have a crontab that looks like this:

* * * * *   /bin/date >> /tmp/every-minute.log
0 8 * * *   /bin/date >> /tmp/eight-am.log

The first line works just fine. The second does not seem to fire at all, no matter what time I set it to run.

The timestamp that is dumped every minute by the first command shows the correct and expected date/time. I have my timezone configured correctly on the raspberry pi.

So why would a cronjob work only if it is set to run every minute and not at a specific time?

  • 2
    This has really nothing to do with raspberry pi – Ingo Mar 30 '18 at 8:08
  • @Ingo, while this is true, I was completely unaware of that fact when I was dealing with the problem. All I knew is that cron jobs weren't behaving like they do on my other Linux devices that I use from day to day. I find that given the nature of raspberry pis, I wipe and start over from fresh installs frequently. As such, I and perhaps others are therefore more likely to face this problem on a RPi than an everyday-use laptop or desktop running a Linux OS. – b_laoshi Apr 1 '18 at 13:24
  • More importantly, problems which disappear after a reboot and cannot be reproduced are unlikely to be of interest to future readers. – Dmitry Grigoryev Apr 3 '18 at 13:45
1

The fix
To answer my own question, cron was unaware of my current timezone. Running sudo /etc/init.d/cron restart fixed everything.

The explanation
Order of events:

  • Booted RPi
  • Used sudo raspi-config to the configure the correct timezone
  • Created cron jobs and tested them; they weren't working

Apparently, cron is unaware of the change in timezone unless you restart the cron service (or restart the whole machine). So when I changed the timezone, cron was still running in the old timezone. Hence, when at 07:59, I configured a job to run at 08:00, it didn't run because cron didn't know it was 08:00. By running sudo /etc/init.d/cron restart, I restarted the cron service at which time it was clued in to the updated timezone.

With cron finally aware of the current timezone, all jobs are now running as scheduled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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