TL;DR (Quick Cron Answers)
- Cron expression (Unix): 
minute hour day-of-month month day-of-week→ 5 fields. - Quartz/Spring variants: often 6 or 7 fields (adds seconds, sometimes year) and special wildcard **
?** for no specific value in DOM/DOW. - Kubernetes CronJob: 
spec.scheduleuses standard cron format; modern clusters supportspec.timeZonefor local time-based schedules. - Best practice: Always test & monitor your cron jobs; log outputs and set alerts for failures.
 
What is Cron?
Cron is a time-based job scheduler in Unix-like systems. It runs commands at specified intervals using cron
expressions. Each line in your crontab declares when and what to run.
Where cron runs:
- System crontab: 
/etc/crontab(has a user field) - User crontab: 
crontab -eper user 
Predefined strings like
@hourly,@daily,@weekly,@monthly,@rebootare shortcuts you can use instead of writing full expressions.
Cron Expression Syntax (Unix / POSIX-style)
Format (5 fields):
┌───────────── minute (0–59)
│ ┌─────────── hour (0–23)
│ │ ┌───────── day of month (1–31)
│ │ │ ┌─────── month (1–12 or JAN–DEC)
│ │ │ │ ┌───── day of week (0–6 or SUN–SAT; 0 or 7 = Sunday on many systems)
│ │ │ │ │
│ │ │ │ │
* * * * *
Wildcards & Operators
*any value,list →1,2,5-range →1-5/step →*/10L,W,#are non-standard extensions (commonly supported by Quartz, not by classic Unix cron).
Examples
- Every 15 minutes: 
*/15 * * * * - Daily at 02:00: 
0 2 * * * - Weekdays at 18:30: 
30 18 * * 1-5 - First day of month at 07:00: 
0 7 1 * * 
Portability tip: Avoid relying on non-standard modifiers unless your scheduler documents them. Classic Unix cron won't accept
?,L,W, or#.
Quartz Cron / Spring Cron vs Unix Cron (Know the Differences)
Many application schedulers (e.g., Quartz, Spring) adopt extended cron syntax:
- Fields: 
seconds minutes hours day-of-month month day-of-week [year]→ 6 or 7 fields - Special 
?: used in day-of-month or day-of-week to mean no specific value - Extended modifiers like 
L(last),W(weekday),#(nth weekday) are commonly supported. 
Quick mapping
- Unix: 
0 2 * * *→ daily 02:00 - Quartz/Spring (with seconds): 
0 0 2 * * ?→ daily 02:00 (no specific DOW) 
Common pitfalls
- Copying a 5-field expression from Unix into Spring/Quartz won’t work. Add seconds (and sometimes year) or use a helper to convert.
 ?is invalid in Unix cron but required in some Quartz scenarios.
Kubernetes CronJobs (k8s)
- Define schedules via 
spec.schedule(standard cron format). - Modern Kubernetes versions support 
spec.timeZone, so you can pin a CronJob to a specific IANA timezone (e.g.,"Europe/Zurich"). Without it, schedules are evaluated in the controller’s local time (often UTC). 
Example
apiVersion: batch/v1
kind: CronJob
metadata:
  name: db-backup
spec:
  schedule: '0 2 * * *' # 02:00 daily
  timeZone: 'Europe/Zurich' # ensure local-time scheduling (supported on modern clusters)
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: OnFailure
          containers:
            - name: backup
              image: alpine:3.20
              command: [ 'sh', '-lc', 'pg_dump $DB_URL > /backups/$(date +%F).sql' ]
Cron Expression Generator / Decoder (Inline)
Use the quick reference below to build or decode schedules. Copy/paste into your crontab or k8s CronJob.
Quick Patterns
| Natural language | Unix cron | Quartz/Spring | 
|---|---|---|
| Every minute | * * * * * | 0 * * * * ? | 
| Every 5 minutes | */5 * * * * | 0 */5 * * * ? | 
| Hourly at :30 | 30 * * * * | 0 30 * * * ? | 
| Daily 02:00 | 0 2 * * * | 0 0 2 * * ? | 
| Weekdays 18:30 | 30 18 * * 1-5 | 0 30 18 ? * MON-FRI | 
| 1st of month 07:00 | 0 7 1 * * | 0 0 7 1 * ? | 
| Sundays 00:00 | 0 0 * * 0 | 0 0 0 ? * SUN | 
| Last day of month 23:00 | (non-standard in Unix) | 0 0 23 L * ? | 
Decode Cheatsheet
- Any 
*/N→ run every N units of that field. - Both DOM and DOW set → behaviour differs by implementation; stick to one (or use 
?in Quartz). 
Crontab Basics
- Edit: 
crontab -e - List: 
crontab -l - Environment: set 
PATH,SHELL,MAILTO, and variables explicitly—cron runs with a minimal environment. - Output: capture with 
>> /var/log/myjob.log 2>&1or rely on system mail. 
Cron Debugging checklist
- Is the command executable when run as the same user?
 - Are absolute paths used for binaries and files?
 - Is the environment (PATH, LANG, TZ) set?
 - Is the expression valid for your scheduler flavor?
 - Are failures monitored/alerted?
 
Monitoring & Reliability
- Pipe outputs to logs and alert on exit codes ≠0.
 - Consider dedicated monitors (health pings, heartbeats) that alert when scheduled runs are missing.
 - In Kubernetes, watch Job statuses, set backoffLimit, and retain some history.
 
Cron FAQs
Unix cron uses 5 fields and doesn’t support ?, L, W, or #. Quartz/Spring use 6–7 fields (adds seconds/year) and allow ? plus date modifiers.
Prepend seconds (usually 0) and use ? in DOM or DOW if the other is specified. Example: Unix 0 2 * * * → Spring 0 0 2 * * ?.
By default schedules are evaluated in the controller’s local time (often UTC). Modern clusters support spec.timeZone to force an IANA timezone like "Europe/Zurich".
Classic cron can’t schedule sub-minute intervals. Use systemd timers, a loop with sleep, application schedulers, or Quartz (with seconds field).
Cron runs with a minimal environment and possibly a different user. Set absolute paths and PATH; test under the same user; log errors explicitly.
Not directly in classic cron. Use two entries (offset by 30 minutes) or a wrapper script with a smarter scheduler.
Use a non-concurrent mechanism in the job code (locks) or configure concurrencyPolicy: Forbid in the CronJob spec.
It means “no specific value” and is valid only in day-of-month or day-of-week fields, typically used when the other is specified.
Usually yes, but predefined strings can differ across implementations; prefer the explicit 5-field form for portability.
Cron Checklist
- Identify your scheduler flavor (Unix, systemd timer, Quartz/Spring, k8s).
 - Normalize expressions to that flavor (5 vs 6/7 fields, special symbols).
 - Pin time zones and DST behavior explicitly.
 - Add monitoring (heartbeat + failure alerts).
 - Document ownership, runbooks, and escalation paths.