问题描述
假设我有一个 crontab,它每 20
分钟运行一次,我有一个小时范围可以变化,所以让我们说 ab
,在一个例子中可能看起来像>
Say I have a crontab which runs every 20
minutes and I have a hour range which can vary so lets say a-b
, which in one example could look like
*/20 5-23 * * * /usr/bin/cool_program
我的问题是,cron 也会在 23:00、23:20、23:40 和 00:00 运行吗?
My question is, will the cron run at 23:00, 23:20, 23:40 and 00:00 too?
推荐答案
GK27 的回答 没有完全回答问题,所以让我澄清一下:
GK27's answer does not fully answer the question, so let me clarify:
cron
将在时间匹配提供的表达式时运行作业.您的表达式告诉它在分钟可被 20 整除 (*/20
) 时运行,您的小时范围告诉它在小时在指定范围内时运行(5-23代码>).剩下的三个
*
告诉它匹配任何一天、一个月和一周中的任何一天.
cron
will run jobs when the time matches the expression provided. Your expression tells it to run when the minute is divisible by 20 (*/20
) and your hour range tells it to run when the hour is within the specified range inclusively (5-23
). The remaining three *
tell it to match any day, month, and any day of the week.
因此第一个作业将在 05:00 运行,因为小时 05
在 5 到 23 的范围内,而分钟 00
可以被 20 整除. 最后一个作业将在 23:40 运行,因为小时 23
在 5 到 23 的范围内,而分钟 40
可以被 20 整除.它将不在 00:00 运行,因为小时 00
不在 5 到 23 的范围内.
Therefore the first job will run at 05:00 because the hour, 05
, is in the range 5 to 23 and the minute, 00
, is divisible by 20. The last job will run at 23:40 because the hour, 23
, is in the range 5 to 23 and the minute, 40
, is divisible by 20. It will not run at 00:00 because the hour, 00
, is not in the range 5 to 23.
这篇关于crontab 小时范围 a-b 也会在 b 之后运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!