【问题标题】:Run a cron job every minute only on specific hours?仅在特定时间每分钟运行一次 cron 作业?
【发布时间】:2012-08-08 12:14:37
【问题描述】:

如何仅在特定时间每分钟运行一次 cron 作业?像这样:

它只会检查从上午 11 点到上午 12 点、下午 4 点到下午 5 点和晚上 9 点到晚上 10 点的每一分钟

对我来说似乎很复杂,我不知道从哪里开始。

【问题讨论】:

    标签: php cron centos


    【解决方案1】:

    根据cron format

    <Minute> <Hour> <Day_of_the_Month> <Month_of_the_Year> <Day_of_the_Week> <Year>
    
    * * * * * *
    | | | | | | 
    | | | | | +-- Year              (range: 1900-3000)
    | | | | +---- Day of the Week   (range: 1-7, 1 standing for Monday)
    | | | +------ Month of the Year (range: 1-12)
    | | +-------- Day of the Month  (range: 1-31)
    | +---------- Hour              (range: 0-23)
    +------------ Minute            (range: 0-59)
    

    解决方案应该是

    * 11,16,21 * * * *
    

    【讨论】:

      【解决方案2】:

      正确的解决方案:

      * 11,16,21 * * *
      

      因为如果你使用以前的解决方案:

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

      作业将于 12:40 或 17:59 开始。它不在上午 11 点到 12 点、下午 4 点到 5 点以及晚上 9 点到 10 点的范围内。

      更新:

      传统(继承自 Unix)cron 格式由五个用空格分隔的字段组成:

      *    *    *    *    *  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 可以使用传统和“增强”版本的 cron 格式,它有一个额外的(第 6 个)字段:Year。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-08-22
        • 2014-10-16
        • 2013-11-27
        • 2018-02-18
        • 2020-07-01
        • 2014-08-07
        • 2015-02-24
        • 2023-03-04
        相关资源
        最近更新 更多