Lesson 10: Cron Jobs

Automating repetitive tasks with Linux schedulers

← Back to Linux Basics and DevOps Automations Page

What is a Cron Job?

Cron is a time-based job scheduler in Linux. It allows DevOps engineers to automate repetitive tasks such as backups, log cleanup, monitoring, and report generation.

Understanding Cron Syntax


* * * * * command
| | | | |
| | | | └── Day of week (0–7)
| | | └──── Month (1–12)
| | └────── Day of month (1–31)
| └──────── Hour (0–23)
└────────── Minute (0–59)
    

Managing Crontab

Common Cron Examples


# Run backup every day at 2 AM
0 2 * * * /scripts/backup.sh

# Clean logs every Sunday
0 3 * * 0 /scripts/cleanup.sh

# Check disk usage every 5 minutes
*/5 * * * * /scripts/disk_check.sh
    

Cron Jobs in DevOps

Best Practices

What You Learned

→ Next: Lesson 11 - Service Automation