Linux & CLIbeginner10 min read

Cron Job Scheduling: Complete Guide

Learn cron expression syntax, common scheduling patterns, how to manage crontabs, and modern alternatives like Kubernetes CronJobs and GitHub Actions schedules.

What is Cron?

Cron is a time-based job scheduler built into every Unix-like operating system. The `crond` daemon runs continuously in the background, checking a configuration file (the crontab) every minute to determine if any scheduled commands should be executed.

Common use cases: - Backups — nightly database dumps or file system snapshots - Report generation — send weekly summary emails every Monday morning - Cache clearing — purge expired sessions or stale CDN content on a schedule - Health checks — ping external services and alert if they go down - Data pipelines — pull data from an API hourly and load it into a warehouse

Cron Expression Syntax

A cron expression has five space-separated fields:

`* * * * * command` `│ │ │ │ └── Day of week (0-7, 0 and 7 = Sunday)` `│ │ │ └──── Month (1-12)` `│ │ └────── Day of month (1-31)` `│ └──────── Hour (0-23)` `└────────── Minute (0-59)`

Special values: - `*` — any value (every) - `,` — list separator: `1,15` means 1st and 15th - `-` — range: `9-17` means 9 through 17 - `/` — step: `*/15` means every 15 units

Common Schedule Patterns

Memorize these patterns and you'll cover 90% of cron use cases:

# Every minute
* * * * *

# Every hour (at minute 0)
0 * * * *

# Every day at midnight
0 0 * * *

# Every weekday (Mon-Fri) at 9:00 AM
0 9 * * 1-5

# Every 15 minutes
*/15 * * * *

# First day of every month at 3:30 AM
30 3 1 * *

# Every Sunday at 2:00 AM
0 2 * * 0

# Twice a day — at noon and midnight
0 0,12 * * *

Managing Crontabs

Each user has their own crontab. Edit it with `crontab -e` (opens in your default editor).

# Edit your crontab
crontab -e

# List current crontab entries
crontab -l

# Remove your crontab (careful — no confirmation!)
crontab -r

# Edit another user's crontab (requires root)
crontab -u www-data -e

# Always capture output to a log file — cron has no terminal
0 3 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1

# Set PATH in crontab — cron's PATH is minimal (/usr/bin:/bin)
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

Cron in Modern Infrastructure

While traditional cron works well for single servers, modern infrastructure offers more robust alternatives:

  • Kubernetes CronJobs — run containerized jobs on a schedule; retries automatically, logs to kubectl, scales with your cluster
  • systemd timers — replace cron on systemd-based Linux; better dependency management and logging via `journalctl`
  • GitHub Actions `schedule` — run CI workflows on a cron schedule; great for nightly tests, stale issue cleanup, or data fetching
  • Cloud schedulers — AWS EventBridge, GCP Cloud Scheduler, Azure Logic Apps; managed, reliable, with no server to maintain
# Kubernetes CronJob — run a job every hour
apiVersion: batch/v1
kind: CronJob
metadata:
  name: hourly-report
spec:
  schedule: "0 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: reporter
            image: myapp/reporter:latest
          restartPolicy: OnFailure

Building Expressions with DevForge

Remembering all the cron syntax details is tricky — especially step values and weekday numbering. The DevForge Cron Expression Generator lets you select schedule components visually and instantly shows the human-readable description ("Every day at 3:00 AM") and the next few execution times.

It's useful for confirming your expression is correct before deploying to production, and for quickly translating existing expressions you encounter in legacy crontabs.

Try it on DevForge

Free online tools related to this tutorial — no signup required.

Related Tutorials