user3610796
user3610796

Reputation: 128

Cron job run every N hours (where 24 isn't evenly divisible by N) doesn't work as expected

For example, if I have a cron job that I want to run every 9 hours:

0 */9 * * * my_script

The job is executed at 00:00, 9:00, and 18:00; and then the same hours the next day.

What I want is for the job to execute at 00:00, 9:00, 18:00; then 03:00, 12:00, 21:00 the next day -- a true "every 9 hours".

Is there any way make cron job run EVERY 9 hours?

Upvotes: 2

Views: 853

Answers (1)

Keith Thompson
Keith Thompson

Reputation: 263617

Specifying */9 means that the job runs every 9 hours starting at 00:00. It starts again at 00:00 every day.

There is no syntax in cron to run a job every 9 hours.

What you can do is run a job every 3 hours, and have the command itself examine the current time and only execute 1 time out of 3. Or it can run every hour and execute one time out of every 9. Don't assume that the current time will be exact; it might run a few seconds after the hour.

Upvotes: 4

Related Questions