Skip to content
cron.surf

Run a cron job on the first Monday of every month

crontab has no exact expression for “First Monday of the month”. Here is why, a workaround, and the platforms that can do it. crontab is the classic Unix scheduler: five time fields and a command, in the server’s time zone.

Why crontab can’t do this exactly

Defined on Quartz as 0 0 9 ? * 2#1 · “At 09:00, on the first Monday of the month”

  • day of week: crontab has no “nth weekday of the month” (2#1).

    WorkaroundRun on the day-of-month part and exit in the job unless it is the right weekday.
    0 9 1-7 * * [ "$(date +\%w)" = "1" ] && /path/to/job
    Not equivalent on its own: it needs a check inside the job.

crontab gotchas

% starts a new lineIn a crontab line an unescaped % ends the command and the rest is sent to stdin. Write \% in date formats.
Day of month OR day of weekWhen both day fields are set, the job runs when either matches, unless one of them starts with *. 0 0 1 * 1 runs on the 1st and on every Monday.
A bare environmentJobs run with a short PATH and no login shell. Use absolute paths and set variables at the top of the crontab.
Missed runs are lostIf the machine is off at the scheduled time, the run is skipped. Use anacron or a systemd timer with Persistent=true if it must catch up.

FAQ

What is the crontab cron expression for “First Monday of the month”?

There is none that matches exactly. crontab has no “nth weekday of the month” (2#1).

Which time zone does a crontab schedule use?

In the server’s local time zone. cronie reads a CRON_TZ= line for the entries below it; check which cron your system runs before you rely on it.

How do I edit my crontab?

Run crontab -e to edit and crontab -l to list. Each line is five time fields followed by the command.

Is Sunday 0 or 7 in crontab?

Both. crontab accepts 0 and 7 for Sunday, and names such as SUN.