0

I have the following cronjob (crontab) running on an amazon ec2 server with Linux AMI:

*/20 8-22 * * * php -q /var/www/html/xxx.php

Unfortunately, the script keeps executing every 20 minutes AFTER 23.00 hour. Could somebody explain what I'm doing wrong?

martin clayton
  • 76,436
  • 32
  • 213
  • 198

1 Answers1

1

There's nothing wrong with your syntax. As you wrote it, the job should execute 45 times every day, the first being at 8:00 and the last being at 22:40.

I have a hunch that the problem is timezone-related: when the job runs at 23:00, cron thinks that the local time is 22:00. If I'm right, then the job won't be running at 8:00 but will start at 9:00 or some later time.

You might be able to confirm this by setting a job like

* * * * * date >> /tmp/cron.date.test

Wait a minute then see if the date in the file agrees with your idea of what time it is. This isn't a perfect test because date will be making its own determination of the timezone separately from cron, but it will inherit its environment from cron so hopefully they'll agree with each other.