我正在尝试学习cron表达式,但是我对一些极端的情况感到困惑。
我试图在一些在线验证器上测试它们,甚至尝试使用python-crontab模块,但是它们给出了不同的结果,这使我更加困惑。
有人会解释以下cron表达式吗?还是验证cron表达式的任何好方法?
我尝试过的在线验证器:
cron表达式需要解释,
59-5/5 * * * *
1/2 * * * *
0 0 1/2 * *
0 0 * 6/2 *
我会说不,这些cron表达式无效。
您不应该使用它们,因为您不确定它们的作用。我已经尝试过了一个1/2 * * * * command
,但是它很有效,但是我不谢谢。我以为它会1 * * * * command
和它一样工作1-59/2 * * * * command
。
也许其中一些作品,但我再说一遍,您不应该使用它们。crontab联机帮助页非常清楚,可以很好地使用范围和步长值:
Ranges of numbers are allowed. Ranges are two numbers separated with a
hyphen. The specified range is inclusive. For example, 8-11 for an ``hours''
entry specifies execution at hours 8, 9, 10 and 11.
Lists are allowed. A list is a set of numbers (or ranges) separated by com-
mas. Examples: ``1,2,5,9'', ``0-4,8-12''.
Step values can be used in conjunction with ranges. Following a range with
``/<number>'' specifies skips of the number's value through the range. For
example, ``0-23/2'' can be used in the hours field to specify command execu-
tion every other hour (the alternative in the V7 standard is
``0,2,4,6,8,10,12,14,16,18,20,22''). Steps are also permitted after an aster-
isk, so if you want to say ``every two hours'', just use ``*/2''.
因此,在使用范围时,必须指定两个数字,并用连字符分隔。范围必须像first-last
这样,如果您想50-15
使用逗号,则更喜欢50-59,0-15
如果要使用步长值,则必须遵循一个范围。
不要比现在更难。对于那些不得不阅读您的作品的人来说,这将变得更加容易。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句