Scheduling Utilities Overview
| Utility | Use Case | Configuration File or Command |
|---|---|---|
| cron | Repetitive jobs (minutes, hours, days) | /etc/crontab & crontab -e |
| anacron | Periodic jobs when system may be off | /etc/anacrontab |
| at | One-time, non-recurring tasks | at <time> / atq / atrm |
1. cron
cron runs tasks on a fixed schedule. The system-wide crontab at /etc/crontab also serves as a syntax reference:
Field Descriptions
- Minute:
0–59 - Hour:
0–23(0 = midnight) - Day of Month:
1–31 - Month:
1–12orjan–dec - Day of Week:
0–6(Sunday = 0 or 7) orsun–sat
*: every valid value,: value list (e.g.,15,45)-: range (e.g.,2-4)/: step (e.g.,*/4for every 4th unit)
Always use full paths in your cron jobs. For example, find
touch with which touch and use /usr/bin/touch.Edit Your User Crontab
- Open the editor:
- Add a job (runs daily at 06:35):
Common cron Examples
- Every Sunday at 03:00:
- On the 15th of each month at 03:00:
- Daily at 03:00:
- Hourly on the hour:
Managing crontabs
| Action | Command |
|---|---|
| List your crontab | crontab -l |
| List root’s crontab | sudo crontab -l |
| Edit another user’s crontab | sudo crontab -u username -e |
| Remove your crontab | crontab -r |
| Remove another user’s crontab | sudo crontab -u username -r |
/etc/cron.* Directories
Place scripts in these directories to run at fixed intervals:
/etc/cron.hourly//etc/cron.daily//etc/cron.weekly//etc/cron.monthly/
2. anacron
When a system is off during a scheduled job,anacron runs missed tasks at boot. The file /etc/anacrontab uses this format:
- period days:
1= daily;7= weekly;@monthly - delay minutes: wait before running
- job-identifier: unique name for logging
- command: full path to execute
test_job every 3 days, 10 minutes after boot.
Verify your configuration without executing jobs:
3. at
Useat for one-off tasks. Schedule in 24-hour or relative formats:
- Absolute:
at '2:30 Aug 20 2022' - Relative:
at 'now + 30 minutes' - Other:
at 'now + 3 days',at 'now + 3 weeks', etc.
Ensure the
atd daemon is running; otherwise at jobs won’t execute.Managing at Jobs
| Action | Command |
|---|---|
| List pending jobs | atq |
| View job details | at -c <job-number> |
| Remove a job | atrm <job-number> |
Practice with these tools to automate backups, cleanup tasks, and custom scripts. Proper scheduling keeps your Linux system reliable and maintenance-free.