"At 05:00 AM, only on Monday"
A cron expression is a string representing a schedule that informs the Cron daemon to execute a task at specific intervals. While they look intimidating at first, they follow a very strict and logical structure.
* * * * * | | | | | | | | | └─ Day of Week (0-6) | | | └─── Month (1-12) | | └───── Day of Month (1-31) | └─────── Hour (0-23) └───────── Minute (0-59)
*
Asterisk: Matches any value (e.g., "every minute").
,
Comma: Defines a list of values (e.g., 1,3,5).
-
Hyphen: Defines a range (e.g., 1-5 for Mon-Fri).
/
Slash: Defines steps (e.g., */15 for "every 15 mins").
0 0 * * *
Run exactly at midnight every day.
0 9-17 * * 1-5
Run at the start of every hour during business hours (9 AM - 5 PM), Mon to Fri.
*/30 9-17 * * *
Run every 30 minutes during business hours, every day.
0 0 1,15 * *
Run at midnight on the 1st and 15th of every month.