Writing a cron expression v7
A cron expression is a text string used to express a schedule of dates and times. The Linux cron tool uses a cron expression to schedule the execution of a job. Replication Server uses the Quartz job scheduling system for scheduling replications.
When creating a schedule for a Replication Server replication system, you can specify a cron expression. There are a number of formats for cron expressions. You must use the cron expression format supported by Quartz.
For a comprehensive treatment of cron expressions, refer to the Quartz documentation.
A Quartz cron expression consists of six mandatory fields followed by one optional field. Each field is separated from its neighbors by one or more consecutive space characters. The fields are order dependent and are listed as they must appear as follows:
ss mi hr dd mm dow [ yyyy ]
Field | Values | Description |
---|---|---|
ss | 0 - 59 | Second of the minute |
mi | 0 - 59 | Minute of the hour |
hr | 0 - 23 | Hour of the day |
dd | 1 - 31 or ? | Day of the month – if dow is given, then dd must be specified as ? |
mm | 1 - 12 or JAN - DEC | Month of the year (3-letter month abbreviations aren't case sensitive) |
dow | 1 – 7 or SUN – SAT or ? | Day of the week – if dd is given, then dow must be specified as ? (3-letter day of the week abbreviations are not case sensitive) |
yyyy | 1970 - 2099 | Year – if omitted, then any year applies |
A number of characters have special meaning that you can use in all fields unless noted.
Character | Meaning | |
---|---|---|
Character | Meaning | Example |
, | Separates a list of values | MON,WED,FRI – Every Monday, Wednesday, and Friday |
- | Separates the low and high end of a range of values | MON-FRI – Every Monday through Friday |
* | Allows all legal values for the field | 0 10 14 * * ? – Every day of every month at 2:10 PM |
x/i | Specifies an increment, i, starting with x | 0 0/10 * * * ? – Every 10 minutes starting on the hour for every day of every month (e.g., 8:00:00, 8:10:00, 8:20:00) |
L | When used in the day of the month (dd) field, means the last day of the month | 0 30 15 L 8 ? – Every August 31st at 3:30 PM |
L | When used by itself in the day of the week field (dow), means Saturday | 30 0 12 ? AUG L – The next Saturday in August at 30 seconds past 12:00 noon |
xxxL | When used in the day of the week field (dow) following a day of the week, means the last xxx day of the month | 30 0 12 ? AUG 6L – The last Friday in August at 30 seconds past 12:00 noon |
xW | Used in the day of the month field (dd) following a day of the month, x, to specify the weekday closest to x without going over into the next or previous month. | 1W – The weekday closest to the 1st of the month. If the 1st is a Wednesday, the result is Wednesday the 1st. If the 1st is a Sunday, the result is Monday the 2nd. If the 1st is a Saturday, the result is Monday the 3rd because the result does not go into the previous or following month. |
xxx#n | Used in the day of the week field (dow) to specify the nth xxx day of the month | 2#3 – The third Monday of the month (2 = Monday, 3 = third occurrence) |
The following are some examples of cron expressions.
Cron expression | Meaning |
---|---|
Cron Expression | Meaning |
0 0 12 20 AUG ? 2009 | 12:00:00 noon on August 20, 2009 |
0 15 13 ? AUG WED | 1:15:00 PM every Wednesday in August |
30 30 8 ? * MON,WED,FRI | 8:30:30 AM every Monday, Wednesday, and Friday of every month |
0 0 8 ? * 2-6 | 8:00:00 AM Monday thru Friday of every month |
0 0/30 8,9,10 15,L * ? | 8:00:00 AM, 8:30:00 AM, 9:00:00 AM, 9:30:00 AM, 10:00:00 AM, 10:30:00 AM on the 15th and the last day of the month of every month |
0 0 9 ? 9 L | 9:00:00 AM each Saturday in September |
0 0 1 ? * MonL | 1:00:00 AM on the last Monday of the month of every month |
0 30 16 15W sep ? | 4:30:00 PM on the weekday of September closest to the 15th |
0 30 16 ? * WED#2 | 4:30:00 PM on the second Wednesday of every month |