
Linux automation on repetitive tasks like backups, cleanups, and system monitoring using cron working in Ubuntu, Debian, CentOS, and AlmaLinux.
Before starting make sure ur linux is ready.
- Ubuntu: ubuntu.com/download
- Debian: debian.org/distrib
- CentOS Stream: centos.org/download
- AlmaLinux: almalinux.org/download
- Talkecho full toturial: Click here
Now we ready to start with Linux automation
What is Cron?
Cron is a time-based job scheduler in Linux. It allows users and administrators to schedule commands or scripts to run at specific times or intervals.
Editing the Crontab
# open user’s crontab
crontab -e
# list current cron jobs
crontab -l
Each line in a crontab represents one job.
Cron Syntax
* * * * * command_to_run
│ │ │ │ │
│ │ │ │ └─ Day of week (0-6, Sun=0)
│ │ │ └─── Month (1-12)
│ │ └───── Day of month (1-31)
│ └─────── Hour (0-23)
└───────── Minute (0-59)
Example: Run a script at 2:30 AM daily:
30 2 * * * /home/user/backup.sh
Examples of Cron Jobs
- System update daily at midnight:
0 0 * * * sudo apt update && sudo apt upgrade -y
- Clean /tmp every week:
0 3 * * 0 rm -rf /tmp/*
- Run a script every 15 minutes:
*/15 * * * * /home/user/script.sh
Viewing Cron Logs
On most systems, cron activity is logged to /var/log/syslog
or /var/log/cron
:
# Debian/Ubuntu
grep CRON /var/log/syslog
# CentOS/AlmaLinux
sudo cat /var/log/cron
Alternative: systemd Timers
Modern Linux distributions also support systemd timers
, which can replace cron for more advanced scheduling:
systemctl list-timers