Using Cron Expressions
Scenarios
A cron expression is a time expression used to specify the execution time, frequency, and interval of a scheduled task. It consists of six fields: Seconds, Minutes, Hours, Day of month, Month, and Day of week.
Field Values
Field |
Allowed Value |
Allowed Special Character |
Remarks |
---|---|---|---|
Seconds |
0–59 |
None |
- |
Minutes |
0–59 |
* / |
The task execution interval is greater than 30 minutes. |
Hours |
0–23 |
- * / |
- |
Dy of month |
1–31 |
- * ? / L |
- |
Month |
1–12 |
JAN-DEC - * / |
- |
Day of week |
1–7 |
SUN-SAT - * ? / L |
The value 1 indicates Sunday, the value 2 indicates Monday, and so on. |
Special Characters
Character |
Description |
Example Value |
---|---|---|
, |
Used to specify additional values. |
1,3,4,7,8. |
* |
Used to select all values within a field. |
If the Minutes field is set to *, an incident is triggered every minute. |
? |
Used to match any value of a field. However, it can be used only in the Day of month and Day of week fields because the two fields affect each other. |
To trigger a scheduled task on the 20th day of each month, regardless of the day of week, use the following format: 13 13 15 20 *? Because the 20th day is specified in the Day of month field, the last character of the Day of week field can only be a question mark (?) instead of an asterisk (*). If the last character is *, it indicates that the incident is triggered on any day of a week, which is exclusive with the 20th day of the date field. In this case, the expression is incorrect. |
- |
Used to specify ranges. |
For the Hours field, the value ranges from 8 to 10, indicating that the incident is triggered every hour from 8:00 to 10:00. |
/ |
Used to specify increments. An incident is triggered from the specified time and at a fixed interval. |
In the Hours field, */3 is equivalent to "every three hours". That is, an incident is triggered at the following time points in a day: 0, 3, 6, 9, 12, 15, 18, and 21. |
L |
Indicates "last". It can appear only in the Day of month and Day of week fields. |
If 5L is used as the value of the Day of week field, the incident is triggered on the last Thursday. |
Example Value
0 15 10 ? * *: indicates that a task is executed at 10:15 a.m. every day.
0 0 10,14,16 * * ?: indicates that a task is executed at 10:00, 14:00, and 16:00 every day.
0 40 9-17 * * ?: indicates that a task is executed at the 40th minute of each hour from 09:00 to 17:00 each day.
0 0/30 10-16 ? * 2: indicates that a task is executed every 30 minutes from 10:00 to 16:00 every Monday.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot