Cron every 3 days: 0 0 */3 * * and what happens monthly
0 0 */3 * * runs on days 1, 4, 7, 10 and so on, eleven times in a 31 day month and ten in every other month. The count resets on the first of each month.
At a glance
- Expression
- 0 0 */3 * *
- Fires
- 11 times in a 31 day month, 10 in every other month, 127 times a year.
- Restricted fields
- Day of month stepped by 3, minute and hour pinned. Month and day of week are open.
- Equivalent macro
- None.
- Days matched
- 1, 4, 7, 10, 13, 16, 19, 22, 25, 28 and, in 31 day months, 31.
- Boundary gaps
- One day after a 31 day month, four days after a 30 day month, one day after February.
In detail
The walk starts at day 1 and adds three, giving ten days in every month and an eleventh, day 31, in the seven months that have one. Because the day of month field never counts past the end of a month, the pattern restarts on the 1st regardless of where the previous month stopped.
That restart produces three different boundary gaps depending on the month. After a 31 day month the last run is the 31st and the next is the 1st, one day later. After a 30 day month the last run is the 28th and the next is the 1st, three days later, which happens to be correct. After a 28 day February the last run is the 28th and the next is 1 March, one day later.
So the schedule is every three days for most of the month and something else at the seams, seven or eight times a year. For a cleanup job or a report that just needs doing regularly that is entirely fine. For anything that computes a window of the last three days it means overlapping or duplicated coverage at every boundary.
The alternative is the same one that fixes every other day: run daily and guard on the epoch day number modulo three. That gives an exact 72 hour cycle that ignores month lengths, at the cost of two thirds of the scheduled runs doing nothing except exiting.
Examples
0 0 */3 * *0 0 2-31/3 * *Days 2, 5, 8 and so on. Ten runs in a 31 day month.
0 0 * * * [ $(( $(date +\%s) / 86400 \% 3 )) -eq 0 ] && /opt/app/bin/job.shThings that catch people out
- The interval is not always three days. It is one day at seven month boundaries a year and three at the others.
- Day 31 only exists in seven months, so the eleventh run happens less than half the time.
- */3 in the day of month field is not the same as */3 in the month field, which gives January, April, July and October.
Try it: Cron Expression Parser
Paste any five or six field expression to get a plain English description, a per field breakdown and the next run times in your local time.
Cron Expression Parser
LOCAL · Browser-OnlyParse cron expressions and see the next scheduled run times
Supports 5-field (minute hour day month weekday), 6-field (with seconds), named values (JAN, MON), and @macros (@daily, @hourly, ...)
Use the dropdowns below to build your cron expression visually, or type a custom value in each field.
Human-Readable Description
Every 5 minutes
Field Breakdown
| Field | Allowed | Value | Meaning |
|---|---|---|---|
| Minute | 0-59 | */5 | every 5 minute(s) |
| Hour | 0-23 | * | every hour |
| Day of Month | 1-31 | * | every day of month |
| Month | 1-12 | * | every month |
| Day of Week | 0-7 | * | every day of week |
Related cron expressions
All cron expressions →Cron every other day: 0 0 */2 * * and the month reset
0 0 */2 * * runs on odd numbered days, 16 times in a 31 day month. The step resets each month, so the 31st and the 1st are consecutive runs.
Cron every 15 days: 0 0 */15 * * gives days 1, 16 and 31
0 0 */15 * * matches days 1, 16 and 31, so 31 day months get three runs and the gap from the 31st to the 1st is a single day.
The cron day of month field: 1 to 31 and missing dates
The day of month field runs 1 to 31, and a date that does not exist in a given month simply never matches. Steps start at 1, giving odd days.
Cron step values: what */n really does
*/n walks a field from its minimum in increments of n. Because it starts at the field minimum, */2 gives even minutes and odd days of the month.
Cron on the first day of the month: 0 0 1 * *
0 0 1 * * runs at midnight on the 1st of every month, twelve times a year, and is exactly what the @monthly macro expands to.
Cron on the 1st and 15th: 0 0 1,15 * *
0 0 1,15 * * runs on the first and fifteenth of every month, 24 times a year. The gaps run from 13 to 17 days, so it is not a fortnight.
Tools for this
- Cron Expression Parser Free online cron expression parser - parse cron expressions and see the next scheduled run times
- Crontab Generator Free online crontab generator - build cron expressions visually with an intuitive interface