DevLearn
Scheduling

Cron Jobs

Cron syntax, Linux crontab, Kubernetes CronJob, and production best practices.

Cron Expression Syntax

Standard 5-field and Quartz 6-field format

Linux cron uses 5 fields: minute hour day-of-month month day-of-week. Quartz/Spring adds optional seconds field (6 or 7 with year). Use online validators before deploying to production.

# Linux crontab (5 fields)
# min  hour  dom  month  dow   command
  0    2     *    *      *     /opt/scripts/backup.sh
  */15 *     *    *      *     /opt/scripts/health-check.sh
  0    9-17  *    *      1-5   /opt/scripts/business-hours-job.sh

# Field values:
# *     any value
# */n   every n units
# n-m   range
# n,m   list
# 0-6   day of week (0=Sunday)

# Spring / Quartz (6 fields with seconds)
# sec  min  hour  dom  month  dow
0     0    2     *    *      ?     # daily at 2 AM
0     0    */4   *    *      ?     # every 4 hours
0     30   9     ?    *      MON-FRI  # weekdays 9:30 AM
Tip: Spring uses Quartz syntax: use ? for "no specific value" when day-of-month and day-of-week conflict.