Introduction
This lesson is about scheduling jobs.
The main question is:
How do you run commands later, once, or on a repeating schedule without sitting at the keyboard?
What you should be able to do after this lesson:
- Understand the difference between
cron,at, and systemd timers. - Create and inspect cron jobs.
- Queue one-time jobs with
at. - Recognize access-control files for cron and at.
- Understand that systemd timers exist as a modern scheduling mechanism.
Big Idea: Different Schedulers Solve Different Timing Problems
At beginner level, keep this picture:
cron= repeat regularlyat= run once later
systemd timer = modern timer unit approach
That is enough to avoid most first-level confusion.
cron
cron is the classic recurring job scheduler.
User crontab
Edit your own cron table:
crontab -e
List it:
crontab -l
Remove it:
crontab -r
Cron Time Fields
A normal cron line has:
minute hour day-of-month month day-of-week command
Example:
0 2 * * * /usr/local/bin/backup.sh
Meaning:
- run every day at 02:00
System Cron Locations
Common places:
/etc/crontab
/etc/cron.d/
/etc/cron.hourly/
/etc/cron.daily/
/etc/cron.weekly/
/etc/cron.monthly/
Simple idea:
- user crontabs are per-user
- system cron locations are for system-wide scheduled tasks
at
at runs a job once at a chosen time.
Queue a job:
at 23:30
Then type commands and finish with Ctrl+d.
Useful commands:
atq
atrm 3
Meaning:
atq= show queued at jobsatrm= remove one queued at job
Access Control
Cron and at can be restricted.
Recognize these files:
/etc/cron.allow
/etc/cron.deny
/etc/at.allow
/etc/at.deny
The idea is simple:
- these files help control who may use the scheduling services
systemd Timers
Modern Linux systems may also use systemd timers.
LPIC expects awareness of them.
You may see:
systemctl list-timers
systemd-run --on-calendar='*-*-* 02:00:00' /usr/local/bin/job.sh
Beginner idea:
- cron is the classic schedule picture
- systemd timers are the modern unit-based picture
Safe Scheduling Habits
Before scheduling a job:
- test the command manually
- use full paths in the scheduled command
- send output to a log file if needed
- verify the schedule actually means what you think it means
This matters because scheduled jobs often fail quietly.
Practice Step by Step
1) Add a simple daily cron job
- Run:
crontab -e - Add:
0 2 * * * /usr/bin/date >> /tmp/cron-test.log - Save the file.
- Verify the installed crontab:
crontab -l
2) Queue a one-time job with `at`
- Run:
at now + 5 minutes - Type:
date >> /tmp/at-test.log - Finish with
Ctrl+d. - Check the queue:
atq
3) Recognize a systemd timer
- Run:
systemctl list-timers - Read it as: a list of timer-based scheduled tasks on the system.
Cheat Sheet
crontab -e= edit user cron jobscrontab -l= list user cron jobs/etc/crontab,/etc/cron.d/= system-wide cron config/etc/cron.hourly/and similar = periodic cron directoriesat= schedule one-time jobatq= list queued at jobsatrm= remove queued at job/etc/cron.allow,/etc/cron.deny= cron access control/etc/at.allow,/etc/at.deny= at access controlsystemctl list-timers= inspect systemd timerssystemd-run --on-calendar=...= run a command through a timer-like schedule
Test Your Knowledge
Complete the quiz to assess your understanding of this course's concepts.
