下面的 cron 表达式是不是每 45 分钟一次? [英] Is the following cron expression means every 45 minutes?
问题描述
我愿意每 45 分钟运行一次脚本(不是每小时的第 45 分钟)
Am willing to run a script every 45 minute (not the :45th minute of every hour)
例如10:00、10:45、11:30、12:15 等.
e.g. 10:00, 10:45, 11:30, 12:15, and so on.
*/45 * * * *
我不确定这是正确的表达方式.
Am not sure this is the correct expression.
推荐答案
我怀疑(我现在很确定)它没有做你想要的:字段是分开的, 和 */45
的分钟数不过是 0,45
.如果 */45
不起作用,我将使用以下三个条目:
I suspect (edit: I'm pretty sure by now) that it doesn't do what you want: fields are separate, and */45
for minutes is nothing more than 0,45
. I would use the following three entries if */45
doesn't do the job:
0,45 0-23/3 * * *
30 1-23/3 * * *
15 2-23/3 * * *
如果您查看 vixie cron 源中的 entry.c
文件,您会注意到每个条目的每个 field 都由 get_list<解析/code> 并表示为该字段允许值的位图.这几乎排除了任何智能"解释,因为
*/45
和 0,45
的区别在这个阶段丢失了......但是有一个 MIN_STAR
标志,设置在 *
的分钟内(包括 */45
).所以我们看一下 cron.c
,一个检查 MIN_STAR
的地方,以了解它与我们的问题无关.现在我们确定 */45
表示每小时的每 45 分钟":0:00、0:45、1:00、1:45 等等
If you take a look at entry.c
file in vixie cron sources, you'll notice that each field of each entry is parsed by get_list
and represented as bitmaps of allowed values for that field. That almost precludes any "smart" interpretation, as the distinction of */45
and 0,45
is lost at this stage... but there is a MIN_STAR
flag, set at the presence of *
in minutes (including */45
). So we take a look at cron.c
, a single place where MIN_STAR
is examined, to learn it's unrelated to our problem. Now we know for sure that */45
means "every 45th minute of every hour": 0:00, 0:45, 1:00, 1:45 and so on.
这里有两个答案自信地说明了相反的情况,引用了手册中的一段不幸的话:
There were two answers here confidently stating the opposite, quoting an unfortunate passage in the manual:
星号后也允许有步骤,所以如果你想说每两个小时",只需使用*/2"
Steps are also permitted after an asterisk, so if you want to say "every two hours", just use "*/2"
我们很幸运拥有 24 小时的一天,其中包含偶数小时,因此无法区分每天从 0:00 开始每两小时一次"和一般每两小时一次".太糟糕了,手册不足以记录非平凡的案例,给人的印象是 * */22
意味着每 22 小时一次.它不是.带有步骤的星号只是使用它的字段中的值列表的简写;它不与其他字段交互.
We are lucky to have a 24 hour day, containing even number of hours, making "every two hours from 0:00, each day" and "every two hours generally" indistinguishable. Too bad that the manual didn't go far enough to document non-trivial cases, making the impression that * */22
means every 22 hours. It does not. Star with a step is just a shorthand for a list of values in the field where it's used; it doesn't interact with other fields.
这篇关于下面的 cron 表达式是不是每 45 分钟一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!