Configuring cron expressions for policies
This section describes how to configure the frequency at which policies run on a schedule using cron expressions.
What is cron
Cron is a standard format for describing a recurring schedule. A schedule consists of one line with five fields separated by spaces. Each field represents a unit of time.
Here's a Template for cron expressions:
┌───────────── минута (0–59)
│ ┌───────────── час (0–23)
│ │ ┌───────────── день месяца (1–31)
│ │ │ ┌───────────── месяц (1–12)
│ │ │ │ ┌───────────── день недели (0–6, где 0—воскресенье)
│ │ │ │ │
* * * * *
When you use a cron expression, the system runs the policy when all fields in the expression match the current time.
Using special characters
You can use specific numbers and special characters in each field.
| 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 the month" and "day of the week," the policy runs 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 the start of the hour; - Hour
9—at 9:00 AM; - Day of the month
*—any day of the month; - Month
*—any month; - Day of the week
1-5—Monday through Friday. The expression means 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 the week
0—on Sundays. The expression means every 30 minutes on Sundays.
You can use the ready-to-use expressions in the table below 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 * |