开发者

crontab syntax query

开发者 https://www.devze.com 2023-03-07 13:53 出处:网络
what does this crontab syntax mean \"*/15 * * * 2-5\" I thought it means it runs every 15 mins past every hour, from Tuesday to Saturday.

what does this crontab syntax mean

"*/15 * * * 2-5"

I thought it means it runs every 15 mins past every hour, from Tuesday to Saturday. can I change that to:

"*/55 * * * 2-5"

that didn't seem to work for some reason.

Can you explai开发者_运维技巧n what is the */ at the beginning ?

Thanks


Your first example should be ok if you want it to run every 15 minutes. 2-5 on the 5th position is referring to Tuesday to Friday.

What do you want to accomplish with */55?

A good syntax explanation can be found in Wikipedia:

Asterisk ( * )

The asterisk indicates that the cron expression will match for all values of the field; e.g., using an asterisk in the 4th field (month) would indicate every month.

Slash ( / )

Slashes are used to describe increments of ranges. For example 3-59/15 in the 1st field (minutes) would indicate the 3rd minute of the hour and every 15 minutes thereafter. The form "*/..." is equivalent to the form "0-59/...".


the */xx means every xx time units.

In your example, */15 means every 15 minutes => :15 :30 :45

The */55 will be every 55 minutes, it will launch the script at 55 after each hour (10:55, 11:55, 12:55....)


"*/15 * * * 2-5"

The */15 does NOT mean it runs every 15 minutes past every hour... the /15 is a step indicator, meaning it runs every 15 minutes (ie. 4 times an hour)

From the man page:

> man 5 crontab

Steps are also permitted after an asterisk, 
so if you want to say ``every two hours'', 
just use ``*/2''.

So only use the */ notation if you want to run something repeatedly, ie. multiple times an hour, multiple times a day, etc.

Peter


contrary to folk lore, */xx does NOT mean every xx time units.

the / pattern means approximately every xx time units, but not at the end of the range.

it only works where xx is evenly divisible by the unit (i.e. for minutes, or seconds, that is only /2, /3, /4, /5, /6, /8, and /12)

for example */5 will repeat every 5 days most of the time except at the ends of months when it repeats after 1, 2, or 4 days, depending on the month and leapyear.

since 55 is so close to 60 it will actually work as you intend, but just by coincidence (because of rounding). if you wrote */25 it would run twice an hour, at :25 and :50


Jaime Guerroro's answer is close to the correct behaviour on RHEL 7.2 Here are my findings. With cron entry as

*/55 * * * * /root/test.sh &>> /root/output.log

I get the behaviour

=== Start /root/test.sh Wed May 18 19:55:01  ===
=== Start /root/test.sh Wed May 18 20:00:01  ===
=== End /root/test.sh Wed May 18 20:02:35  ===
=== End /root/test.sh Wed May 18 20:03:44  ===

Explanation from wiki, https://en.wikipedia.org/wiki/Cron

for example, entering */5 for the day field sometimes executes after 1, 2, or 3 days, depending on the month and leap year; this is because cron is stateless (it does not remember the time of the last execution nor count the difference between it and now, required for accurate frequency counting-- instead, cron is a mere pattern-matcher).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号