A cron job is a time-based task scheduler in Unix-like operating systems that automatically runs commands or scripts at specified intervals without any manual intervention.
A cron job is a scheduled task managed by the cron daemon, a background service that runs continuously on Unix and Linux systems. The name comes from the Greek word 'chronos', meaning time. It was first introduced in Unix in the 1970s and remains one of the most widely used automation tools in software engineering and system administration today.
Each cron job is defined by a single line called a cron expression, made up of five time fields followed by the command to execute: minute (0–59), hour (0–23), day of month (1–31), month (1–12), and day of week (0–7). For example, '30 9 * * 1' runs a task every Monday at 9:30 AM. Wildcards (*), commas (for lists), hyphens (for ranges), and slashes (for step values) give you fine-grained scheduling control.
Cron jobs are stored in a configuration file called a crontab (cron table), which each user can manage via the 'crontab -e' command. The cron daemon reads these files and triggers the appropriate jobs at the correct times. System-wide crontabs also exist in /etc/cron.d/ and /etc/crontab, which can include a user field for specifying which account runs the command.
Cron jobs are used for automating repetitive tasks such as database backups, log rotation, sending scheduled emails, cache invalidation, report generation, and running data pipelines. They are a core part of DevOps and backend engineering workflows. Many modern platforms like AWS EventBridge, GitHub Actions, and Kubernetes CronJobs provide cloud-native equivalents built on the same scheduling concept.
A common mistake is assuming cron jobs run in the same shell environment as your user session; they do not inherit your PATH or other environment variables, so always use absolute paths to commands and scripts. Redirect stdout and stderr to a log file (e.g., '>> /var/log/myjob.log 2>&1') to capture output for debugging. Ensure your script is idempotent — safe to run multiple times — and use file locks (via 'flock') to prevent overlapping executions if a job runs longer than its interval.
© RM Full Stack & AI Engineer · All guides · Roadmaps · Open the app