[Reprint] crontab to run every hour

crontab run once per hour

First gave the crontab syntax

 

For many online timed writing tasks given hour, we can say that the vast majority are wrong! For this example, the following wording:

00 * * * * # executed once every hour 
00 * / 1 * * # * above the same task

This is right for you? Control syntax given foremost point of view, this timing task 0, hourly, daily, monthly, weekly execution, seems very reasonable ah? One hour before the 0 and 0 after an hour apart one hour is not it? So not that every hour to perform it? A closer look, it seems a bit wrong, why it is 0 per hour? If I create a scheduled task in 11:55, want to perform every hour, then the next task is the timing of the implementation of the 12:55, 12:00 or execution? Clearly, the implementation of which is 0 per hour, which is executed at 12:00.

It seems to be no difference? Consider then the next, every 3 hours to perform how to write?

Online writing is given as follows:

0 * / 3 * * * # erroneous writing is performed once every 3 hours

This is the wrong wording, which can be fully demonstrated in front of one hour to perform a sense of confusion brought about by such an approach is in fact the entire three hours of each 0 once. In other words, it will be every day at 3:00, 9:00, 12:00 and so on ... integer multiple time points 3 to perform, not every three hours to perform the true sense, as similar to the front, if you are 11 : 56 creating this scheduled task every three hours, then it will begin execution at 12:00 instead of 14:56 execution. See the following verification:

11:56 minutes to create so-called "every three hours to perform the" timing of the above tasks:

 

After 4 minutes instead of 3 hours, crontab timing of the tasks performed:

 

In fact, for this "0 * / 3 * * *" This minute time point is fixed, every hour or 3 hours according to the wording hour, are counted beginning from 1:00 multiples, such as every hour is 1:00, 2:00, 3:00, and 2:00 is every 2 hours, 4:00, 6:00, 3:00 is every 3 hours, 6:00, 9:00, etc., and so on.

In addition, given that there are people online every hour of the regular tasks of writing:

* * / 1 * * * # Wrong executed once every hour, every minute in fact executed

This kind of not as good as than the front, which they not every hour, every minute but performs! why? Because minutes are required to perform every minute, hour and every hour was required to perform, it is clearly time two policy conflicts. The final minutes to prevail, so it is executed once per minute.

 

真正的每隔一小时、每隔105分钟执行的定时任务应该如何写呢?如下:

* / 60 * * * * # per 60 minutes every hour 
* / 105 * * * * # performed every 105 minutes

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/11703589.html