Cron · Both fields restricted → run when either matches (OR)

Day-of-month and day-of-week together

When both day fields are restricted, Vixie-style cron runs the job if either field matches.

Key facts

Vixie ruleBoth fields restricted → run when either matches (OR)
UnrestrictedA field beginning with * is treated as unrestricted
Example<code>0 0 1 * 1</code> = the 1st of the month OR every Monday
AND semanticsNot expressible directly in a five-field line
QuartzUses <code>?</code> in one day field instead of OR
POSIXDoes not define this combination for all implementations

The rule people misread

A line such as 0 0 1 * 1 does not mean “the first day of the month when it is a Monday”. It runs on the first of every month and on every Monday. The reason is that both day fields are restricted, and the classic implementation runs the command when either set matches the current day.

If one of the two fields is *, the other field alone decides. That is why 0 0 * * 1 is unambiguously “every Monday”.

How to get an AND schedule

When the job really must satisfy both conditions, put the check inside the command: run daily at midnight and exit unless the weekday is Monday and the day is 1–7, or run on every Monday and test the day-of-month. The second form produces at most one run and is easier to reason about.

Quartz avoids the ambiguity by requiring ? in one of the day fields, which makes the intent explicit. Porting a five-field line with two restricted day fields into Quartz is therefore not a mechanical translation.

Frequently asked questions

Does cron use AND or OR for day fields?

Vixie-style cron uses OR when both day-of-month and day-of-week are restricted. Quartz requires one of them to be ? instead.

How do I run on the first Monday of the month?

Five-field cron cannot express it directly. Run every Monday and exit from the script unless the date is 1–7, or use a scheduler with richer calendar rules.

What counts as a restricted day field?

In the classic implementation a field beginning with an asterisk is unrestricted; any other value restricts it.

New tools, straight to your inbox

One short email when we add tools worth using. No spam, unsubscribe anytime.