Interview Prep/Shell Scripting/cron and systemd timers

Explain the five cron time fields with examples.

BeginnerConceptcron and systemd timers
Answer
┌ minute (0-59)
│ ┌ hour (0-23)
│ │ ┌ day of month (1-31)
│ │ │ ┌ month (1-12)
│ │ │ │ ┌ day of week (0-7, 0 and 7 = Sunday)
* * * * * command
*/5 * * * *     every 5 minutes
30 2 * * *      02:30 every day
0 9 * * 1-5     09:00 on weekdays
0 0 1 * *       midnight on the 1st of each month
15 */6 * * *    at minute 15 every 6 hours
@reboot         once at startup (Vixie/cronie)

Gotcha: if both day-of-month and day-of-week are restricted, cron runs when either matches (0 0 1 * 1 = the 1st and every Monday).

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on cron and systemd timers