Tools › Cron examples › the last day of the month
Cron expression for the last day of the month
The cron expression for the last day of the month is:
What it does
Cron cannot express 'last day' directly. This schedule fires on days 28 to 31, and the command must check whether tomorrow is the 1st.
Field by field
| Field | Value | Meaning |
|---|---|---|
| Minute | 0 | exactly 0 |
| Hour | 0 | exactly 0 |
| Day of month | 28-31 | range 28-31 |
| Month | * | every value |
| Day of week | * | every value |
Typical uses
End-of-month billing and closing tasks.
Watch out for
Use: 0 0 28-31 * * [ "$(date -d tomorrow +\%d)" = "01" ] && /path/to/job. The \% escape is required because a bare % means newline in crontab.
Add it to your crontab
crontab -e, then add:
0 0 28-31 * * /path/to/command >> /var/log/myjob.log 2>&1