β° Scheduling Tasks (cron)
Sometimes, you want tasks to run automatically at a specific time instead of doing them manually. Linux gives you cron and at for this.
Think of it like setting reminders or alarms for employees:
Cron β repeating tasks (daily, weekly)
At β one-time tasks
4a. cron Jobs
What it does: Schedules repeated tasks.
Analogy: You assign a janitor to clean the office every day at 6 PM automatically.
Crontab syntax:
* * * * * command_to_run - - - - - | | | | | | | | | +---- Day of the week (0-7, Sun=0 or 7) | | | +------ Month (1-12) | | +-------- Day of the month (1-31) | +---------- Hour (0-23) +------------ Minute (0-59)
Runs backup.sh every day at 7:00 AM
Managing cron jobs:
- crontab -e β edit current user's cron jobs
- crontab -l β list current user's cron jobs
- crontab -r β remove all cron jobs
4b. at Command
What it does: Schedules one-time tasks at a specific time.
Analogy: You ask an employee to send a report exactly at 3 PM today, but not again tomorrow.
Runs report.sh once at 3 PM today
Tip: You can also enter interactive mode:
List and remove at jobs:
- atq β list pending jobs
- atrm <job_number> β remove a job
Real-life analogy
β
Key takeaway:
cron β repeating/scheduled tasks
at β one-time tasks
We've now covered all 4 topics of Process Management:
1. Viewing Running Processes
2. Killing or Stopping Processes
3. Managing Background/Foreground Jobs
4. Scheduling Tasks
If you want, I can create a visual cheat-sheet that shows all commands with analogies for quick recallβit's super handy for practice. Do you want me to do that?