Hands-on Lab·CompTIA Linux+
cron, timers, and one-off jobs
Domain 4 names scheduled tasks. This guide installs a cron job and waits for it, reads the environment cron actually gave it, writes the same job as a systemd timer with its service and timer units, asks systemd when a schedule will next fire, and runs a genuine one-off - then removes all of it.
Automation and Scripting Guide 19 of 28 Intermediate
- OSUbuntu 26.04 LTS
- Kernel7.0.0-30-generic
- systemd259
- Mandatory access controlAppArmor on Ubuntu, SELinux enforcing on Alma
- TimeAbout 26 min
- Firewallufw / nftables 1.1.6 - firewalld / nftables 1.1.5
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| LPLUS-A01 | 192.168.0.73 | Ubuntu 26.04 LTS | Debian-family host - apt, ufw, netplan, AppArmor | 2 Core | 4 GB | 50 GB |
This guide includes
Use this for the scheduling marks. This matters because a scheduled job fails over the environment it was handed far more often than over its schedule - and that environment is measured here three ways.
- installing a crontab, and reading its five fields
- measuring the three environments a job can be given
- finding the four other places a cron job can live
- writing a systemd timer, which is two files, and seeing what it gives you that cron does not
- scheduling a one-off job, both ways
Before you start
- a-script-a-repo-and-a-container
-
A user crontab, and where it actually lives
-
What cron actually gave the job
-
The same job as a systemd timer
-
Asking when a schedule fires
-
A one-off job
-
Putting the machine back