簡體   English   中英

僅在特定時間每分鍾運行一次cron作業?

[英]Run a cron job every minute only on specific hours?

你如何只在特定時間每分鍾運行一次cron作業? 像這樣:

它僅在上午11點至中午12點,下午4點至下午5點以及晚上9點至晚上10點每分鍾檢查一次

這對我來說似乎很復雜,我不知道從哪里開始。

正確解決方案

* 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。

按照cron格式

<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 * * * *

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM