An online generator for Cron: www.pppet.net/
A cron expression is a string of six or seven fields separated by five or six Spaces. Each field represents a meaning. Cron has two syntax formats:
Seconds Minutes Hours Day Month Week Year
Seconds Minutes Hours Day Month Week
Minutes Hours Day Month Week
The characters that can appear in each field are as follows:
Code Seconds: indicates that == Seconds ==; The value is an integer ranging from 0 to 59. Minutes: indicates == Minutes ==. The value is an integer ranging from 0 to 59. Hours: indicates that == Hours ==. The value is an integer ranging from 0 to 23. The value can contain four characters: – * / Day: == Day ==. Can appear, – * /? L W C An integer ranging from 0 to 31. Value: Month: indicates that == Month ==. A string of four characters, including – * /, is an integer ranging from 1 to 12, or Jan-dec Week: == Week ==; Can appear, – * /? L C # is a four-character integer ranging from 1 to 7, or the SUN-SAT range. 1 indicates Sunday, 2 indicates Monday, and so on. Year: indicates Year. Can appear, – * /, valid from 1970 to 2099
Each field uses numbers, but the following special characters can also appear, which mean:
-
* : matches any value in the field. If * is used in the Minutes field, events are emitted every minute.
-
? : Applies only to the Day and Week fields. Because Day and Week are mutually exclusive, when one of the two subexpressions is specified, the value of the other subexpression is set to “?” to avoid conflicts. .
For example, if you want to trigger scheduling on the 20th of each month, you can only use the following command: 13, 13, 15, 20 *? , the last digit can only be used? If * is used to indicate that the trigger is triggered no matter what day of the week, which is not the case.
-
– : indicates the range. For example, if 5-20 is used in the Minutes field, it is triggered every minute from 5 to 20 Minutes
-
/ : indicates that the firing starts at the start time, and then at fixed intervals (increments of specified values). For example, using 5/20 in the Minutes field means firing every 5 Minutes, 25,45, and so on.
-
, : lists enumeration values. For example, using 5,20 in the Minutes field means firing at 5 and 20 Minutes per minute.
-
In the Day subexpression, “L” stands for the last Day of a month. In the Week self-expression, “L” stands for the last Day of a Week, that is, SAT (Saturday). If “L” is preceded by a specific content, it has other meanings. For example, “6L” stands for the sixth to last day of the month. Note: Do not specify lists or ranges when using the “L” argument, as this can cause problems
-
W: indicates a valid working Day (Monday to Friday). The system triggers an event on the latest valid working Day to the specified Day.
For example, if 5W is used on Day, if 5th falls on Saturday, it will trigger on the nearest working Day: Friday, 4th. If the 5th falls on a Sunday, it is triggered on the 6th; If the 5th falls on a day between Monday and Friday, it is triggered on the 5th. Another point is that the recent search for W does not cross months
LW
: The two characters can be used together to indicate the last working day of a month.#
: Specifies the day of the month. This parameter can only be used in the Week field. For example, 2#3 is the second Wednesday of a month.
A few examples:
-
0, 0, 2, 1 star? * : Indicates that tasks are scheduled at 2:00 a.m. on the first day of each month
-
0 to 15 10? * : Mon-FRI indicates that the job will be executed at 10:15 am every day from Monday to Friday
-
0 to 15 10? 6L 2002-2006: Indicates the last Friday of each month from 2002-2006 at 10:15 am
-
0, 0, 10,14,16 * *? : Every day at 10 a.m., 2 p.m., 4 p.m
-
0 0/30 9-17 * *? : Every half hour during nine to five working hours
-
0 0 12? * WED: 12:00 noon every Wednesday
-
0, 0, 12 * *? : Triggered at 12 noon every day
-
0 to 15 10? * * : Triggered daily at 10:15 am
-
0, 15, 10 * *, right? : Triggered every day at 10:15 a.m
-
0, 15, 10 * *, right? * : Triggered every day at 10:15 a.m
-
0, 15, 10 * *, right? 2005: Triggered at 10:15 am every day in 2005
-
0 times 14 times * *, right? : triggers every minute between 2pm and 2:59pm each day
-
0 0/5, 14 * *, right? : triggers every 5 minutes between 2 p.m. and 2:55 p.m. every day
-
0/5 14,18 * *? : triggers every 5 minutes between 2 p.m. and 2:55 p.m. and 6 p.m. and 6:55 p.m. each day
-
0 0-5 14 * *? : triggers every minute between 2pm and 2:05pm each day
-
0 to 10, 44 14? 3 WED: Triggered at 2:10 PM and 2:44 PM on Wednesdays of March every year
-
0 to 15 10? * Mon-FRI: Triggered Monday through Friday at 10:15 am
-
0, 15, 10, 15 times? : Triggered at 10:15 am on the 15th of each month
-
0 15 10 L * ? : Triggered at 10:15 am on the last day of each month
-
0 to 15 10? * 6L: Triggered at 10:15 am on the last Friday of every month
-
0 to 15 10? * 6L 2002-2005: Triggered on the last Friday of each month from 2002 to 2005 at 10:15 am
-
0 to 15 10? * 6#3: Triggered at 10:15 am on the third Friday of each month