Cron midnight is the server's midnight, not yours
You write 0 0 * * *, you read it as “midnight”, and you mean the midnight you
are standing in. The server means its own. On a machine running UTC those two are
three hours apart for a large part of the year, and the report that should have
been waiting at breakfast is not there until ten.
This is not a cron bug. It is the one thing cron never says out loud: the schedule is read against the system clock of the machine that runs the job.
Which clock the server is on
Look before you guess. Every one of these answers the same question:
dateon the server prints the local time and the offset it is using.cat /etc/timezoneprints the zone name, such asEtc/UTCorEurope/Kyiv.- On a container, the zone is usually UTC, because the image ships without one.
A container is the usual trap. Your laptop is on local time, the container is on UTC, and the crontab inside it was copied from your laptop. If the zone is wrong and the machine is yours, how to change cron’s timezone walks through the switch.
Set the hour you actually meant
You have three honest options, and they are not equally good.
- Pick the UTC hour that matches the hour you want. Midnight in Kyiv in summer is
0 21 * * *in UTC. The schedule is correct and stays correct until the offset changes. - Set the zone for the job. Some crontabs accept
CRON_TZ=Europe/Kyivabove the line, but it is an extension: the same crontab may reject the line, or ignore the variable, on another system. - Run the job in a wrapper that fixes the zone itself. It is more work, and it is the only form that survives a different cron.
If the job runs on the hour your users notice, the naive form is the one that
looks right and reads wrong. 0 0 * * * is a fine expression. It is just not a
promise about the hour you meant.
Check the expression before you paste it
Two minutes of reading is cheaper than a missed report:
- Paste the line into the parser and read it field by field.
- Build the schedule you described in the generator and look at the next run times on your own clock.
- Find the cadence you are after in the schedule library — every entry there carries the trap it hides.
The clock is the server’s. The expression is yours.