Cron writes the time of a repeating job in five fields. It is easy to read, but if you do not verify that the expression yields the time you want and which time zone applies, the job may run at the wrong moment. Here are common examples and the points to watch.
The five fields, quickly
A standard cron expression has five fields in the order minute hour day month weekday. Minutes run 0 to 59, hours 0 to 23, days 1 to 31, months 1 to 12 and weekdays 0 to 7 (both 0 and 7 mean Sunday). * means every value, , lists, - is a range and / is a step.
The fields are combined with AND, so the job runs at moments when all conditions hold. There is one exception: when both the day and the weekday are specified, usually the job runs if either one matches.
*/15 means every 15, as in 0, 15, 30, 45.
1-5 means Monday through Friday.
Some systems add seconds or a year field and use six or more fields, so check the notation of your tool.
Common examples
Every hour on the hour is 0 * * * *, every five minutes is */5 * * * *, and 3:30 every morning is 30 3 * * *. Weekdays at 9:00 is 0 9 * * 1-5, and weekends at noon is 0 12 * * 6,0.
Midnight on the first of each month is 0 0 1 * *, the first day of each quarter is 0 0 1 1,4,7,10 *, and Mondays at 8:00 is 0 8 * * 1. Every 30 minutes during working hours is */30 9-18 * * 1-5, but check whether 18:30 should run as well.
0 */2 * * * runs at 0, 2, 4 ... 22 o'clock. For odd hours use 0 1-23/2 * * *.
0 0 * * 0 is midnight every Sunday.
After writing an expression, always check the next several run times in a tester.
When day and weekday are both set
With 0 9 1 * 1, many people expect it to run only when the first of the month is a Monday, but the standard behavior is to run on the first of the month or on any Monday. It therefore runs far more often than intended.
If you truly need both conditions, check the date inside the job rather than in the expression. For example, the first Monday of a month is hard to express. A simple way is to run every Monday and have the job confirm at the start that today's date is 7 or less.
Specifying day 31 skips months that have no 31st.
For end-of-month runs, run daily and check whether tomorrow is the first.
Leaving one of day and weekday as * makes the intent clearer.
Time zones and daylight saving
Cron times follow the time zone of the system running the job. If the server is on UTC, 0 9 * * * is 6 p.m. in Korea. Writing an expression without checking the server time zone is the most common cause of wrong runs.
In zones with daylight saving time, a job scheduled in the skipped hour is missed on the day clocks go forward, and a job in the repeated hour may run twice on the day they go back. Avoiding the early hours around 1 to 3, or keeping the server on UTC, is safest.
Korea has no daylight saving time and stays at UTC+9, so the arithmetic is simple.
If you serve users in many countries, run on UTC and convert only the display to local time.
Compare UTC and local time in the Unix timestamp converter on this site to see the difference clearly.
Overlapping runs and checking
If the next start time arrives before a job finishes, two copies run at once. Use a file lock or make the job skip if one is already running, and choose an interval comfortably longer than the usual run time.
When many jobs gather at the top of the hour, server load rises. Where possible, offset the minute, as in 7 * * * *. Keep results in logs and send an alert on failure so jobs do not stop silently.
Record the start and end times inside the job.
Test a new schedule at a short interval first, then change it to the real one.
Look at the next five run times in the cron parser to confirm they match your intent.