如何从10-19开始每两小时设置一次Cron作业 [英] How to set a Cron job in Every two hour from 10-19

查看:141
本文介绍了如何从10-19开始每两小时设置一次Cron作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在1个月前对此有疑问。那是1小时的间隔,我得到了确切的答案。以下是旧问题的链接

I had a question before 1 month regarding this. that was the interval of 1 hour and i got exact answer. below is the link to the old question

如何在9时每隔一小时设置Cron作业:上午00到下午6:00(星期一至星期五)

谢谢您 Stack Over Flow 和贡献者 Andy Holmes

现在,我对Cron表达式有了新的要求,就像我每2个小时需要一次。

Now I got a new requirement on Cron expression, the same way i need it in every 2 hour.

我已经尝试过


0 9 / 2-18 / 2 * * 1-5

0 9/2-18/2 * * 1-5


0 (9-18)/ 2 * * 1-5

0 (9-18)/2 * * 1-5

但这没有帮助,请帮助我

But that doesn't help, Please help me

推荐答案

使用:

0 10-18/2 * * 1-5

您指定小时范围 9-18 ,然后 / 2 表示要在 2 小时内步进。手册页对此进行了非常清楚的解释:

You specify the hour range 9-18 and then /2 to mean step by 2 hours. The man page explains this pretty clearly:


步长值可以与范围结合使用。在带有 / 的范围之后,指定该范围内数字值的跳跃。例如,可以在小时字段中使用 0-23 / 2 指定每隔一小时执行一次命令(V7标准中的替代方法是 0 ,2,4,6,8,10,12,14,16,18,20,22 )。星号后也可以执行步骤,因此,如果您想说每两个小时,只需使用 * / 2

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 execution 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 asterisk, so if you want to say "every two hours", just use */2.

如果您的界面不允许使用此速记,则必须手动列出它们:

If your interface doesn't allow this shorthand, you have to list them out by hand:

0 10,12,14,16,18 * * 1-5

这篇关于如何从10-19开始每两小时设置一次Cron作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆