Linucate
~ Linucate_

107.2 Automate System Administration Tasks

All Levels

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 regularly
at = 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 jobs
  • atrm = 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:

  1. test the command manually
  2. use full paths in the scheduled command
  3. send output to a log file if needed
  4. 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
  1. Run: crontab -e
  2. Add: 0 2 * * * /usr/bin/date >> /tmp/cron-test.log
  3. Save the file.
  4. Verify the installed crontab: crontab -l
2) Queue a one-time job with `at`
  1. Run: at now + 5 minutes
  2. Type: date >> /tmp/at-test.log
  3. Finish with Ctrl+d.
  4. Check the queue: atq
3) Recognize a systemd timer
  1. Run: systemctl list-timers
  2. Read it as: a list of timer-based scheduled tasks on the system.

Cheat Sheet

  • crontab -e = edit user cron jobs
  • crontab -l = list user cron jobs
  • /etc/crontab, /etc/cron.d/ = system-wide cron config
  • /etc/cron.hourly/ and similar = periodic cron directories
  • at = schedule one-time job
  • atq = list queued at jobs
  • atrm = remove queued at job
  • /etc/cron.allow, /etc/cron.deny = cron access control
  • /etc/at.allow, /etc/at.deny = at access control
  • systemctl list-timers = inspect systemd timers
  • systemd-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.