
Learn how to automate tasks on Linux with cron
(repeated jobs) and at
(one-time jobs). Works on 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
Why Schedule Tasks?
- Run backups automatically.
- Clean logs or temporary files.
- Send reports at specific times.
- Restart services or scripts when needed.
Using cron for Repeated Jobs
cron
runs jobs at specific intervals. Each user can have their own crontab.
Edit your crontab
crontab -e
Format: minute hour day month day-of-week command
# run every day at midnight
0 0 * * * /home/alex/backup.sh
# run every Monday at 6am
0 6 * * 1 /usr/bin/python3 /home/alex/report.py
# run every 5 minutes
*/5 * * * * /usr/local/bin/check.sh
List your cron jobs:
crontab -l
Special Cron Keywords
@reboot run at startup
@hourly run every hour
@daily run once a day
@weekly run once a week
@monthly run once a month
Example: Run script at boot:
@reboot /usr/local/bin/startup.sh
Using at for One-Time Jobs
The at
command runs jobs once at a specific time.
# run script at 10 PM tonight
at 10pm -f /home/alex/script.sh
# run tomorrow at 7:30 AM
echo "/home/alex/backup.sh" | at 7:30am tomorrow
List scheduled jobs:
atq
Remove a job:
atrm JOB_ID
Checking Logs
Cron logs can help you debug:
- Ubuntu/Debian:
/var/log/syslog
- CentOS/AlmaLinux:
/var/log/cron