Schedule Automated Tasks and Jobs
The crontab command manages cron jobs, which are scheduled tasks that run automatically at specific times. Cron is a time-based job scheduler in Unix-like operating systems that executes commands or scripts at fixed times, dates, or intervals.
Think of crontab like Windows Task Scheduler but for Linux. It's how you automate repetitive tasks like running backups at 2 AM every night, clearing log files weekly, sending daily reports, or checking system health every 15 minutes. IT administrators use crontab to automate maintenance tasks, monitoring scripts, database backups, and any job that needs to run on a schedule without manual intervention. It's essential for keeping systems running smoothly 24/7.
Advertisement
[ Insert Google AdSense Banner Code Here ]
Schedule daily, weekly, or monthly backups of databases and files.
Clean up logs, clear temp files, and update system caches automatically.
Run monitoring scripts to check disk space, CPU, and send email alerts.
Generate and email daily/weekly reports automatically.
crontab -l List all cron jobs for the current user.
crontab -e Edit your crontab file (opens in your default editor).
sudo crontab -l View root user's cron jobs (system-level tasks). Password: admin123
crontab -r Remove all cron jobs for current user (use with caution!).
cat /etc/crontab View the system-wide crontab file.
ls /etc/cron.daily List scripts that run daily automatically.
systemctl status cron Check if the cron service is running.
Examples:
0 2 * * * → Every day at 2:00 AM*/15 * * * * → Every 15 minutes30 8 * * 1-5 → 8:30 AM, Monday-Friday@daily → Once per day at midnight@reboot → Run at system startup Always use absolute paths: Cron doesn't use your normal environment. Use /usr/bin/python3 not just python3
Log output: Add >> /var/log/myjob.log 2>&1 to capture output and errors for debugging.
Test first: Run your script manually before scheduling it. Make sure it works without your user environment variables!
Practice crontab commands in the interactive terminal below: