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).
More on cron and systemd timers
What is different about the environment a cron job runs in?BeginnerWhat is the difference between a user crontab, `/etc/crontab`, `/etc/cron.d/` and `/etc/cron.daily/`?IntermediateHow do you prevent overlapping cron runs and capture output properly?IntermediateWhat is a systemd timer and how does it compare to cron?IntermediateWrite a minimal systemd service and timer that run a backup at 02:30 daily.IntermediateWhat is the difference between `OnCalendar=`, `OnBootSec=` and `OnUnitActiveSec=`?Advanced