Cron expression for the first of every month
0 0 1 * *The job runs once a month, at 00:00 on the 1st, twelve times a year. Many crons also accept @monthly.
Runs when: minute 0; hour 0; day of month 1; every month; any day of week.
Change it in the cron expression generatorHow the five fields read
| Field | Value | Reads as |
|---|---|---|
| Minute | 0 | at 0 |
| Hour | 0 | at 0 |
| Day of month | 1 | at 1 |
| Month | * | every value |
| Day of week | * | every value |
The next five runs
What people use it for
- Generating monthly invoices or statements
- Resetting monthly usage quotas
- Archiving the previous month's data
There is no "last day of the month"
Standard cron cannot say the last day, and a job set for the 31st skips every month with 30 days or fewer. The usual fix is to run every day and have the script exit unless tomorrow is the 1st. AWS EventBridge does accept L in the day-of-month field for the last day, which cron on Linux does not.
Variations of the first of every month
| Expression | What it does |
|---|---|
0 6 1 * * | The 1st of the month at 06:00. |
0 0 1,15 * * | Twice a month, on the 1st and the 15th. |
0 0 1 */2 * | Every other month on the 1st: January, March, May and so on. |
The same schedule in four tools
Linux crontab
0 0 1 * * /path/to/commandAdd it with crontab -e. It runs in the machine's time zone.
Kubernetes CronJob
spec:
schedule: "0 0 1 * *"
timeZone: "Etc/UTC"
concurrencyPolicy: ForbidtimeZone is stable from Kubernetes 1.27. Without it, the controller's time zone applies. Forbid stops a new run starting while the last one is still going.
GitHub Actions
on:
schedule:
- cron: '0 0 1 * *'Schedules run in UTC from the default branch, and a run can start a few minutes late when GitHub is busy. Scheduled workflows in public repositories are disabled after 60 days without repository activity.
AWS EventBridge
cron(0 0 1 * ? *)EventBridge uses six fields, with a question mark in one of the two day fields, and rules run in UTC. Weekday numbers start at Sunday = 1, so names such as MON are safer than numbers.
Questions about the first of every month
- How do I run on the last day of the month?
- Run daily from the 28th and check tomorrow's date: 0 0 28-31 * * [ "$(date -d tomorrow +\%d)" = 01 ] && /path/to/command (GNU date). On AWS EventBridge, use cron(0 0 L * ? *), because L means the last day.
- Is @monthly the same as 0 0 1 * *?
- In Vixie cron, yes. Kubernetes CronJobs accept it too, but GitHub Actions and EventBridge do not.
Nearby schedules
- Cron expression for every Sunday at 2 AM: Weekly instead of monthly.
- Cron expression for every quarter: Four times a year, on the first of the quarter.
- All schedules and the generator
Scheduling jobs, pipelines and cloud infrastructure is part of my DevOps engineering work.