Configuring cron expressions for policies
This section describes how to configure policy schedules 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 a cron expression Template:
┌───────────── минута (0–59)
│ ┌───────────── час (0–23)
│ │ ┌───────────── день месяца (1–31)
│ │ │ ┌───────────── месяц (1–12)
│ │ │ │ ┌───────────── день недели (0–6, где 0—воскресенье)
│ │ │ │ │
* * * * *
When you use a cron expression, the system triggers the policy 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 you specify both the “day of month” and “day of week,” the policy triggers on days that match either condition.
Cron expression examples
The elements of the expression 0 9 * * 1-5 have the following meanings:
- Minute
0—at minute zero; - Hour
9—at hour nine; - Day of month
*—any day; - Month
*—any month; - Day of 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 meanings:
- Minute
*/30—every 30 minutes (at :00 and :30); - Hour
*—every hour; - Day and month
*—any day and month; - Day of week
0—on Sundays. The overall meaning of the expression is every half hour on Sundays.
To configure policies, you can use the ready-made expressions in the table below.
| 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 * * |
| At 5:00 PM every weekday | 0 17 * * 1-5 |
| Once a week—Sunday at 11:00 PM | 0 23 * * 0 |
| Every 15 minutes during business 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 * |