你如何只在特定时间每分钟运行一次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点 .
UPDATE:
传统的(从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可以使用传统版本和"enhanced"版本的cron格式,其中还有一个(第6个)字段:Year .
根据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 回答
正确解决方案
因为如果您使用以前的解决方案
工作将在12:40或17:59开始 . 它不在上午11点至中午12点,下午4点至下午5点以及晚上9点至晚上10点 .
UPDATE:
传统的(从Unix继承)cron格式由五个由空格分隔的字段组成:
nnCron可以使用传统版本和"enhanced"版本的cron格式,其中还有一个(第6个)字段:Year .
根据cron format
解决方案应该是