Run a cron job every minute only on specific hours?

后端 未结 2 2068
时光取名叫无心
时光取名叫无心 2020-12-31 01:00

How do you run a cron job every minute only on specific hours? Like so:

It will only check every minute from 11AM to 12AM, 4PM to 5PM and 9PM to 10PM<

2条回答
  •  一生所求
    2020-12-31 01:42

    Right solution:

    * 11,16,21 * * *
    

    Because if you use previous solution:

    0-59 11-12,16-17,21-22 * * * *
    

    Job will start at 12:40 or 17:59. It is not in range from 11AM to 12AM, 4PM to 5PM and 9PM to 10PM.

    UPDATE:

    Traditional (inherited from Unix) cron format consists of five fields separated by white spaces:

    *    *    *    *    *  command to be executed
    ┬    ┬    ┬    ┬    ┬
    │    │    │    │    │
    │    │    │    │    │
    │    │    │    │    └───── day of week (0 - 6) (0 is Sunday, or use names)
    │    │    │    └────────── month (1 - 12)
    │    │    └─────────────── day of month (1 - 31)
    │    └──────────────────── hour (0 - 23)
    └───────────────────────── min (0 - 59)
    

    nnCron can use both traditional and "enhanced" version of cron format, which has an additional (6th) field: Year.

提交回复
热议问题