All Products
Search
Document Center

CloudOps Orchestration Service:Configure CRON expressions

最終更新日:Jun 20, 2024

This topic describes how to configure CRON expressions.

CRON expressions are applicable to one-time tasks that need to be complete at a specific point in time, recurring tasks, and routine maintenance tasks. A CRON expression is a string that represents time. The string consists of five spaces and six fields, which is in the X X X X X X format. X is a field placeholder. If a field contains multiple values, the values are separated by commas (,). Each field can contain a specific value or special characters that have logical representations.

Field values

The following table describes valid values and supported special characters for each field in CRON expressions.

Field

Required

Value range

Supported special character

Second

Yes

[0, 59]

N/A

Minute

Yes

[0, 59]

Commas (,) and forward slashes (/) are supported in some scenarios. If you use a comma (,) to separate two values, the interval between the two values must be greater than or equal to 30 minutes. If you use a forward slash (/) to separate two values, the latter value must be greater than or equal to 30 minutes.

Hour

Yes

[0, 23]

* , - /

Day-of-month

Yes

[1, 31]

* , - / ? L

Month

Yes

[1, 12] or [JAN, DEC]

* , - /

Day-of-week

Yes

[1, 7] or [SUN, SAT]. If you use [1, 7], 1 indicates Sunday and 2 indicates Monday.

* , ?

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 Day-of-week field, an asterisk (*) indicates every day of a week.

,

Lists enumerated values.

In the Minute field, 5,40 indicates that the task is triggered at the 5th and 40th minutes of an hour.

-

Indicates a range.

In the Day-of-month field, 5-20 indicates that the task is triggered every day from the 5th day to the 20th day of a month.

/

Indicates increments.

In the Day-of-month field, 1/5 indicates that the task is triggered every five days from the first day of a month. In the Hour field, 3/8 indicates that the task is triggered every 8 hours from the 3rd hour of a day.

?

Indicates that the field is not specified. Only the Day-of-month and Day-of-week fields support this character.

If you specify the Day-of-month or Day-of-week field, you must set the other field to a question mark (?) to prevent conflicts.

L

Indicates the last day. Only the Day-of-month field supports this character. Do not specify a list or range if you use the L character. Otherwise, a logical disorder may be caused.

In the Day-of-month field, L indicates the last day of a month.

Examples

The following table describes examples of CRON expressions.

Example

Description

0 15 10 ? * *

Runs the task at 10:15 every day.

0 15 10 * * ?

Runs the task at 10:15 every day.

0 0 12 * * ?

Runs the task at 12:00 every day.

0 0 10,14,16 * * ?

Runs the task at 10:00, 14:00, and 16:00 every day.

0 0/40 9-17 * * ?

Runs the task every 40 minutes from 09:00 to 17:00 every day.

0 0 12 ? * WED

Runs the task at 12:00 every Wednesday.

0 15 10 15 * ?

Runs the task at 10:15 on the 15th day of every month.

0 15 10 L * ?

Runs the task at 10:15 on the last day of every month.

0 0,30 14 ? 3 WED

Runs the task at 14:00 and 14:30 every Wednesday in March every year.

0 0 1 ? * 4#1

Runs the task at 01:00 on the first Wednesday of every month.