Adam Grant
Adam Grant

Reputation: 13105

Cron not working with minutes

(Update: apparently there are no seconds in cron jobs. However, my question now becomes: what explains the cron behaving this way? Thank you)

I have two cron triggers, one is supposed to come in just moments before the other one.

First I had task 1 come in every 59 seconds

*/59 * * * * ?

And task 2 come in every 59 seconds, but offset by 15 seconds.

15/59 * * * * ?

This worked fine. No complaints. Now I want to just move this values over to the minutes column. This time, there is only a minute offset, which is negligible since the task repeats every 59 minutes.

Task 1

* */59 * * * ?

Task 2

* 1/59 * * * ?

Suddenly, task 1 is constantly firing and task 2 doesn't fire at all. The change described above seems to be the only thing affecting this.

Upvotes: 1

Views: 2883

Answers (2)

Cory Kendall
Cory Kendall

Reputation: 7304

* */59 * * * means run every minute (the first * is minutes) in the current hour, and then wait 59 hours to run again.

* 1/59 * * * means run every minute in the first hour (which you are not in, hence task 2 never fires) and then run every minute in the hour 50 hours later.

I think the problem is still the seconds/minutes confusion.

EDIT: Note some versions of Cron will not accept a number preceding a '/'... it must be a range. So for your use case I would use */59 * * * * and 1-59/59 * * * *

Upvotes: 2

Brian Roach
Brian Roach

Reputation: 76908

Because there are no seconds

*    *    *    *    *  command to be executed
┬    ┬    ┬    ┬    ┬
│    │    │    │    │
│    │    │    │    │
│    │    │    │    └───── day of week (0 - 7) (Sunday=0 or 7)
│    │    │    └────────── month (1 - 12)
│    │    └─────────────── day of month (1 - 31)
│    └──────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)

http://en.wikipedia.org/wiki/Cron

Upvotes: 1

Related Questions