loading image
Back to glossary

Cron Job

Scheduled automated task that runs at regular intervals on Unix/Linux systems, essential for operations automation.

Updated on January 25, 2026

A Cron Job is a scheduled task that executes automatically at predefined times on Unix and Linux systems. Using the cron daemon, it enables automation of repetitive operations such as backups, system maintenance, email sending, or temporary file cleanup. This technology is fundamental for efficient management of modern infrastructures.

Fundamentals

  • Crontab syntax with 5 time fields (minute, hour, day of month, month, day of week) followed by the command to execute
  • Cron daemon that checks the scheduled task table every minute to trigger corresponding jobs
  • Configuration files stored in /etc/crontab or /var/spool/cron/crontabs depending on users
  • User permission management with individual and system crontabs to secure execution

Benefits

  • Complete automation eliminating repetitive manual interventions and reducing human errors
  • Maximum scheduling flexibility with support for complex patterns and varied time expressions
  • Proven reliability over decades with stable implementation present on all Unix/Linux systems
  • Low system resource consumption with minimal overhead compared to alternative solutions
  • Integrated logging facilitating debugging and auditing via syslog or custom output files

Practical Example

crontab-examples.sh
# Edit current user's crontab
crontab -e

# Daily backup at 2:30 AM
30 2 * * * /usr/local/bin/backup-database.sh >> /var/log/backup.log 2>&1

# Clean temporary files every Sunday at midnight
0 0 * * 0 find /tmp -type f -mtime +7 -delete

# Server health check every 15 minutes
*/15 * * * * /usr/local/bin/health-check.sh

# Monthly report on the 1st at 9 AM
0 9 1 * * /usr/local/bin/monthly-report.py --email admin@example.com

# Weekly restart on Monday at 3 AM (maintenance)
0 3 * * 1 /usr/sbin/service application restart

# List active cron jobs
crontab -l

Implementation

  1. Identify repetitive tasks requiring automation and define their optimal execution frequency
  2. Create execution scripts in bash, Python, or other language, including error handling and logging
  3. Manually test each script to validate its operation before automatic scheduling
  4. Define appropriate crontab syntax using tools like crontab.guru to verify expressions
  5. Add the task via 'crontab -e' specifying absolute paths for commands and files
  6. Configure output redirection (stdout/stderr) to log files to facilitate monitoring
  7. Monitor execution via system logs and set up alerts for failures
  8. Document each cron job with comments in the crontab to facilitate future maintenance

Pro tip

Always use absolute paths in your cron jobs as the execution environment is minimal (limited PATH). Define necessary environment variables at the beginning of crontab (PATH, SHELL, MAILTO) and test your scripts with 'env -i' to simulate the restricted cron environment. For critical applications, implement a locking mechanism (flock) to prevent concurrent executions.

  • crontab.guru - Visual cron expression editor and validator with natural language explanations
  • systemd timers - Modern alternative to cron jobs on recent Linux systems with better dependency management
  • anacron - Cron extension for machines not running 24/7, executing missed tasks at startup
  • cronie - Modern cron implementation with improved notification and security support
  • Kubernetes CronJobs - Cloud-native equivalent for orchestrating scheduled tasks in containers
  • cron-utils - Java library to parse, validate, and manipulate cron expressions programmatically

Cron Jobs remain an essential pillar of system automation, offering a proven, lightweight, and universal solution for orchestrating recurring tasks. Mastering them significantly reduces operational costs, improves infrastructure reliability, and frees technical teams for higher-value activities. In a modern DevOps context, they integrate seamlessly with CI/CD pipelines and Infrastructure as Code strategies.

Themoneyisalreadyonthetable.

In 1 hour, discover exactly how much you're losing and how to recover it.

Web development, automation & AI agency

contact@peaklab.fr
Newsletter

Get our tech and business tips delivered straight to your inbox.

Follow us

© PeakLab 2025