Configuring cron expressions for policies
This section describes how to configure the frequency at which policies run on a schedule by using cron expressions.
What is cron
Cron is a standard format for describing recurring schedules. A schedule consists of one line with five fields separated by spaces. Each field represents a unit of time.
Here's the cron expression Template:
┌───────────── минута (0–59)
│ ┌───────────── час (0–23)
│ │ ┌───────────── день месяца (1–31)
│ │ │ ┌───────────── месяц (1–12)
│ │ │ │ ┌───────────── день недели (0–6, где 0—воскресенье)
│ │ │ │ │
* * * * *
When you use a cron expression, the policy runs when all fields in the expression match the current time.
Using special characters
You can use special characters in each field in addition to specific numbers.
| Character | Meaning | Example | Description |
|---|---|---|---|
* | any value | * * * * * | every minute |
, | list of values | 0 9,18 * * * | at 9:00 AM and 6:00 PM |
- | range of values | 0 9-17 * * * | every hour from 9:00 AM to 5:00 PM |
/ | step | */15 * * * * | every 15 minutes |
You can combine characters. For example, the expression 0 9-17/2 * * 1-5 means "every 2 hours from 9:00 AM to 5:00 PM on weekdays."
If both the "day of the month" and "day of the week" are specified, the policy runs on days that match either condition.
Cron expression examples
The elements of the expression 0 9 * * 1-5 have the following values:
- Minute
0—at minute zero; - Hour
9—during the ninth hour; - Day of the month
*—any day of the month; - Month
*—any month; - Day of the week
1-5—Monday through Friday. The overall meaning of the expression is every weekday at 9:00 AM.
The elements of the expression */30 * * * 0 have the following values:
- Minute
*/30—every 30 minutes (at :00 and :30); - Hour
*—every hour; - Day and month
*—any day and month; - Day of the week
0—on Sundays. The overall meaning of the expression is every half hour on Sundays.
You can use the ready-made expressions in the following table to configure policies.
| When to run the policy | Cron expression |
|---|---|
| Every minute | * * * * * |
| Every 5 minutes | */5 * * * * |
| Every hour (at the start of the hour) | 0 * * * * |
| Every day at 12:00 AM (midnight) | 0 0 * * * |
| Every day at 9:00 AM | 0 9 * * * |
| Every weekday at 9:00 AM | 0 9 * * 1-5 |
| Every Monday at 9:00 AM | 0 9 * * 1 |
| Twice a day—at 9:00 AM and 6:00 PM | 0 9,18 * * * |
| Every Saturday and Sunday at 12:00 PM | 0 12 * * 0,6 |
| On the first day of every month at 12:00 AM | 0 0 1 * * |
| The last working hour of every weekday | 0 17 * * 1-5 |
| Once a week—Sunday at 11:00 PM | 0 23 * * 0 |
| Every 15 minutes during working hours on weekdays | */15 9-18 * * 1-5 |
| Every quarter (January 1, April 1, July 1, and October 1 at 12:00 AM) | 0 0 1 1,4,7,10 * |