How to set a Cron job in Every two hour from 10-19

喜你入骨 提交于 2019-12-12 07:04:54

问题


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

How to set a Cron job in Every one hour from 9:00 am to 6:00 pm ( Monday to Friday )

Thank you Stack Over Flow and the contributor Andy Holmes

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

I have tried

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

and

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

But that doesn't help, Please help me


回答1:


Use:

0 10-18/2 * * 1-5

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

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


来源:https://stackoverflow.com/questions/26031450/how-to-set-a-cron-job-in-every-two-hour-from-10-19

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!