下面的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)
*/45 * * * *
不确定这是否是正确的表达式。
Am not sure this is the correct expression.
推荐答案
我可疑(编辑:我现在很肯定),它不做你想要的:字段是分开的, code> * / 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
将注意到每个条目的每个字段由 get_list
解析并且表示为该字段的允许值的位图。这几乎排除了任何聪明的解释,因为 * / 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屋!