When you run a Cloud Assistant command, you can call an API operation and use the Timed and Frequency parameters to set when to run the Cloud Assistant command. The value of the Frequency parameter is a cron expression. This parameter specifies the frequency of scheduled tasks, frequency of routine maintenance, and the point in time at which to complete a one-time task.
Introduction
A cron expression is a string that represents time. The string consists of five or six spaces and six or seven fields, which is in the X X X X X X X
format. X
is a placeholder of a field. The last filed that indicates the year is not required and can be left empty. If a field contains multiple values, the values are separated by commas (,
). Each field can be a specific value or special characters that have logical representations. Each field supports a maximum of one leading zero.
0 15 8 ? * * 2022
or 0 15 08 ? * * 2022
but cannot be specified to 0 15 008 ? * * 2022
. Field values
The following table describes valid values and supported special characters for each field in cron expressions.
Field | Required | Valid value range | Special character |
Second | Yes | [0, 59] | * , - / |
Minute | Yes | [0, 59] | * , - / |
Hour | Yes | [0, 23] | * , - / |
Day | Yes | [1, 31] | * , - / ? L W |
Month | Yes | [1, 12] or [JAN, DEC] | * , - / |
Week | Yes | [1, 7] or [MON, SUN]. If you use the [1, 7] format, 1 indicates Monday and 7 indicates Sunday. | * , - / ? L # |
Year | No | [Current year ,2099] | * , - / |
Special characters
Each field in a cron expression can contain a specific number of special characters. Each special character represents a logical argument.
Special character | Description | Example |
* | Indicates all valid values. | In the Month field, an asterisk (* ) indicates every month. In the Week field, an asterisk (* ) indicates every day of the week. |
, | Lists enumerated values. | In the Minute field, 5,20 indicates that the task is triggered once at both the 5th and 20th minutes. |
- | Indicates a range. | In the Minute field, 5-20 indicates that the task is triggered once every minute from the 5th to 20th minute. |
/ | Indicates increments. | In the Minute field, 0/15 indicates that the task is triggered once every 15 minutes from the beginning of an hour. In the Minute field, 3/20 indicates that the task is triggered once every 20 minutes from the 3rd minute of an hour. |
? | Indicates an unspecified value. Only the Day and Week fields support this character. | If the Day or Week field is specified, the other field must be set to a question mark (? ) to prevent conflicts. |
L | Indicates the last day of a specific period. Only the Day and Week fields support this character. Note To prevent logic errors, do not specify a list or range when you use the L character. |
|
W | The weekday that is nearest to the specified day of the month. The weekday that the W character indicates is in the same month as the specified day of the month. LW indicates the last weekday of the specified month. | If 5W is specified in the Day field and the 5th day of the month falls on Saturday, the task is triggered on Friday, which is the 4th day of the month. If the 5th day of the month falls on Sunday, the scheduled task is triggered on Monday, which is the 6th day of the month. If the 5th day of the month falls on a weekday, the scheduled task is triggered on the 5th day of the month. |
# | A specific day of a specific week in every month. Only the Day of a week field supports this character. | In the Week field, 4#2 indicates the second Thursday of a month. |
Examples
The following table describes some example values of cron expressions.
Example | Description |
0 15 10 ? * * | Executes the task at 10:15 every day. |
0 15 10 * * ? | Executes the task at 10:15 every day. |
0 0 12 * * ? | Executes the task at 12:00 every day. |
0 0 10,14,16 * * ? | Executes the task at 10:00, 14:00, and 16:00 every day. |
0 0/30 9-17 * * ? | Executes the task every half an hour between 09:00 and 17:00 every day. |
0 * 14 * * ? | Executes the task every minute between 14:00 and 14:59 every day. |
0 0-5 14 * * ? | Executes the task every minute between 14:00 and 14:05 every day. |
0 0/5 14 * * ? | Executes the task every 5 minutes between 14:00 and 14:55 every day. |
0 0/5 14,18 * * ? | Executes the task every 5 minutes between 14:00 and 14:55 and between 18:00 and 18:55 every day. |
0 0 12 ? * WED | Executes the task at 12:00 every Wednesday. |
0 15 10 15 * ? | Executes the task at 10:15 on the 15th day of every month. |
0 15 10 L * ? | Executes the task at 10:15 on the last day of every month. |
0 15 10 ? * 6L | Executes the task at 10:15 on the last Saturday of every month. |
0 15 10 ? * 6#3 | Executes the task at 10:15 on the third Saturday of every month. |
0 10,44 14 ? 3 WED | Executes the task at 14:10 and 14:44 every Wednesday in March every year. |
0 15 10 ? * * 2022 | Executes the task at 10:15 every day in 2022. |
0 15 10 ? * * * | Executes the task at 10:15 every day every year. |
0 0/5 14,18 * * ? 2022 | Executes the task every 5 minutes between 14:00 and 14:55 and between 18:00 and 18:55 every day in 2022. |
0 15 10 ? * 6#3 2022,2023 | Executes the task at 10:15 on the third Saturday of every month from 2022 to 2023. |
0 0/30 9-17 * * ? 2022-2025 | Executes the task every half an hour between 9:00 and 17:30 every day from 2022 to 2025. |
0 10,44 14 ? 3 WED 2022/2 | Executes the task at 14:10 and 14:44 every Wednesday in March every 2 years starting from 2022. |