Cron syntax is short, which makes mistakes easy to write and slow to notice. Two classic ones:
1. * 9 * * * is not "once at 9am"
The first field is minutes, and * means every minute. So this runs 60 times, from 09:00 to 09:59. If you want once a day at nine, you need 0 9 * * *.
2. 0 9 1 * 1 is not "Mondays that fall on the 1st"
When both day-of-month and day-of-week are restricted, standard cron treats them as OR, not AND. This runs at 09:00 on the 1st of every month and on every Monday. If you really want "the 1st, only if it's a Monday", the usual trick is to schedule on Mondays and test the date inside the command, e.g. 0 9 * * 1 [ "$(date +\%d)" = "01" ] && ./job.sh (note the escaped % — crontab treats a bare % as a newline).
A few other gotchas
- Time zone: many servers and hosted schedulers (GitHub Actions included) run cron in UTC, so "9am" may be 2:30pm in India.
- Step values like
*/7in the minute field restart every hour (…:49, :56, then :00), so they aren't truly "every 7 minutes". - Some systems accept extensions (
L,W,?, a seconds field) that plain crontab rejects.
The safest habit is to look at the next few run times before deploying. Disclosure: I run GoToolsOnline, which has a free cron generator that explains an expression in plain English and lists the next 10 runs in your time zone or UTC: https://gotoolsonline.com/tools/cron-generator
Top comments (0)