Crontab First Day of Month (0 0 1 * *)
Run a cron job on the 1st of every month at midnight. The standard monthly schedule for billing, reporting, and data archival.
Detailed Explanation
Running a Cron Job on the First of Every Month
The expression 0 0 1 * * schedules a job at midnight on the first day of every month. This is equivalent to the @monthly shorthand.
Field Breakdown
| Field | Value | Meaning |
|---|---|---|
| Minute | 0 | At minute 0 |
| Hour | 0 | At midnight |
| Day of Month | 1 | On the 1st |
| Month | * | Every month |
| Day of Week | * | Any day of the week |
The @monthly Shorthand
@monthly is equivalent to 0 0 1 * *. Both run at midnight on the first day of each month. Use whichever form your team finds more readable.
Last Day of the Month
Scheduling for the last day of the month is trickier because months have different lengths (28, 29, 30, or 31 days). Some cron implementations support the L symbol:
0 0 L * * # Last day of every month (non-standard)
For portable solutions, you can use a script-based check:
0 0 28-31 * * [ "$(date -d tomorrow +\%d)" = "01" ] && /scripts/month-end.sh
Mid-Month Schedules
For the 15th of every month: 0 0 15 * *
For both the 1st and 15th: 0 0 1,15 * *
Use Case
Monthly execution is standard for billing cycle jobs, generating monthly invoices, rotating monthly logs, archiving old data, running monthly database maintenance, sending monthly newsletters, and calculating monthly KPIs.