Usage [turn] cron expression

 

cron expression by specific rules specified time for regular tasks, simply record some of its syntax and examples, not entirely, to cover most of their daily needs.

 

 

 

1. The overall structure

 

cron expression is a string, divided into six or seven fields, each separated by a space between two domains, which syntax is:

 

'S domain and domain-day time-domain domain domain week of May domain domain "

 

Among them, the domain can be omitted, represent a year when omitted.

 

 

 

2. Each domain range

 

domain name Possible values Preferably symbols (column only partially used)
The seconds field An integer of 0 to 59   *    -    ,    /
Fenwick An integer of 0 to 59   *    -    ,    /
Time Domain An integer of 0 to 23   *    -    ,    /
Day range An integer of 1 to 31,   *    -    ,    /    ?    L
Domain month Or an integer of 1 to 12 JAN ~ DEC   *    -    ,    /
Zhou domain Or an integer of 1 to 7 SUN ~ SAT   *    -    ,    /    ?    L    # 
In the domain It is an integer of 1970 to 2099   *    -    ,    /

 

 

 

3. The significance of symbols

 

(1) * can represent all the values ​​that match the domain;

 

For example, "0013 * *?" Indicates that the implementation of a daily 13 points.

 

(2)? Must appear in cron expressions and can only occur once, on the day with a domain or domain week, represents uncertain value, not the limit value;

 

It differs from * that does not match all values ​​on that domain, such as specifying a March every Friday, so Friday March 4 may be value;

 

For example, "0056 *?" Represents the 6th of each month at 5 o'clock executed regardless of the week, "005? * 3" every Wednesday at 5 o'clock and perform a few numbers either.

 

(3) - represents a range in the match field;

 

For example, "? 0309-15 * *" indicates that the daily 9: 30-15: 30 is performed once per hour, "01-5 * * 1?" Indicates that every Sunday 1-5 minutes per each hour minutes once.

 

(4) shows enumeration value;

 

For example, "00 8,16,23? * 1,7" indicates that each of Saturday and Sunday 8:00, 16:00, 23:00 time of each execution.

 

(5) / represents the start time and time interval;

 

For example, "00 * 3/5 *?" Indicates 3 o'clock every day started, is performed once every five hours, i.e. 3:00, 8:00, 13:00, 18:00, 23:00 is executed once,

 

"* / 5 * * * *?" Means every 5 seconds to perform a "0 * / 1 * * *?" Means every minute once.

 

(6) it can only be used on the periphery of domain #, # behind the digital representation of a few weeks, if the value of the week does not exist, is not performed;

 

For example, "000? * 5 # 2" indicates the second Thursday of each month the implementation of the zero point, "15,306? * 7 # 5" indicates the fifth Saturday of each month to perform 6:30:15 If a month does not exist the fifth Saturday, is not performed.

 

Represents the last day of the month, if used without the first circumferential region numerals Saturday, indicated by numbers in the last cycle value (7) L domain only for days or weeks field for the date field;

 

For example, "0 0 23 L *?" Represents the last day of each month 23:00 executed, "0 0 23? * L" represents every Saturday 23:00 executed, "0 0 23? * 3L" represents the last month Tuesday's 23 points execution.

 

 

 

4. Some common examples (not double quotes)

 

significance expression
 Executed once every 5 seconds            */5  *  *  *  *  ?
 Executed once every minute            0  */1  *  *  *  ?
 1:00 executed once a day     0  0  1  *  *  ?
 23:55 executed once a day     0  55  23  *  *  ?
 The last day of each month 23:00 executed once     0  0  23  L  *  ?
 Saturday 8:00 execution time     0  0  8  ?  *  L
 The last Friday of every month, every two hours to perform a     0  0  */2  ?  *  6L
 Third Friday of each month at 10:15 am execution time     0  15  10  ?  *  5#3
 Execute every 1 minute during the day at 2:00 pm to 2:05 pm     0  0-5  14  *  *  ?
 Said on Monday through Friday at 10:15 am every day to perform     0  15  10  ?  *  2-6
 每个月的最后一个星期五上午10:15执行     0  15  10  ?  *  6L 
 每天上午10点,下午2点,4点执行一次     0  0  10,14,16  * * ?
 朝九晚五工作时间内每半小时执行一次     0  0/30  9-17  *  * ?
 每个星期三中午12点执行一次     0  0  12  ?  *  4
 每年三月的星期三的下午2:10和2:44各执行一次       0  10,44  14  ?  3  4 
 每月的第三个星期五上午10:15执行一次     0  15  10  ?  *  6#3
 每月一日凌晨2点30执行一次     0  30  2  1  *  ?
 每分钟的第10秒与第20秒都会执行     10,20  *  *  *  * ?
 每月的第2个星期的周5,凌晨执行     0  0  0  ?  *  6#2

 

 


---------------------
作者:西班牙乞丐
来源:CNBLOGS
原文:https://www.cnblogs.com/dubhlinn/p/10740838.html
版权声明:本文为作者原创文章,转载请附上博文链接!
内容解析By:CSDN,CNBLOG博客文章一键转载插件

Guess you like

Origin www.cnblogs.com/admans/p/11963645.html