What this is
cron is a scheduler that runs commands automatically at specific times.
What it is for
- Automated backups
- Cleanup tasks
- Periodic scripts
Prerequisites
- SSH access
- A command or script you want to schedule
Step-by-step
Step 1) Edit your user crontab
crontab -e
Step 2) Add a cron line (example: every day at 2:30 AM)
30 2 * * * /usr/bin/bash /home/USERNAME/scripts/backup.sh >> /home/USERNAME/logs/backup.log 2>&1
What it does: Runs the script and appends output to a log.
Step 3) Verify cron syntax (basic)
- Minute (0-59)
- Hour (0-23)
- Day of month (1-31)
- Month (1-12)
- Day of week (0-7, Sunday)
Step 4) Test your script manually first
/usr/bin/bash /home/USERNAME/scripts/backup.sh
Warnings & notes
- Cron runs with a minimal environment. Always use full paths.
- Log output to debug problems.
Final verification
crontab -l
ls -la /home/USERNAME/logs/backup.log
Conclusion
cron lets you automate maintenance reliably. Start simple, log output, and verify results.