每分钟只在特定时间运行cron作业? [英] Run a cron job every minute only on specific hours?
问题描述
如何在特定时间内每分钟运行cron作业?像这样:
How do you run a cron job every minute only on specific hours? Like so:
它将只检查从上午11点到上午12点,下午4点到下午5点以及晚上9点到晚上10点的每分钟
It will only check every minute from 11AM to 12AM, 4PM to 5PM and 9PM to 10PM
对我来说似乎很复杂,我不知道从哪里开始。
It seems to be complicated to me I don't know where to start.
推荐答案
正确的解决方案:
* 11,16,21 * * *
因为如果您使用以前的解决方案:
Because if you use previous solution:
0-59 11-12,16-17,21-22 * * * *
工作将从12:40或17:59开始。
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.
更新:
传统(继承自Unix)cron格式包含由空格分隔的五个字段:
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 可以使用传统和增强版本的cron格式,其中有第6个字段:Year。
nnCron can use both traditional and "enhanced" version of cron format, which has an additional (6th) field: Year.
这篇关于每分钟只在特定时间运行cron作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!