Study Hub / CompTIA Linux+ (XK0-006) / Domain 4.0
CompTIA Linux+ (XK0-006) Domain 4.0: Automation, Orchestration, and Scripting — Explained
Domain 4.0 is about making Linux do the boring work for you: shell scripts that repeat tasks perfectly, schedulers that run them on time, and orchestration that scales the pattern to hundreds of machines. The most "force multiplier" domain on the exam.
Shell scripting: the fundamentals
- What a script is — a text file of commands the shell executes in order. The shebang (
#!/bin/bash) declares which interpreter runs it; the execute bit lets it run directly. - Variables — named storage:
NAME="web1"assigns,$NAME(or${NAME}) expands. No spaces around=— the shell is unforgiving about that. - Exit statuses — every command returns a number:
0means success, anything else means failure. Scripts branch on this:$?holds the last command's status. - Conditionals and loops —
iftests a condition;foriterates over a list;whilerepeats until a condition changes. Together they turn command lists into programs. - Quoting — double quotes allow variable expansion ("$HOME"); single quotes prevent it ('$HOME' stays literal). One of the most-tested scripting details.
- stdin, stdout, stderr — every process has three streams: input (0), output (1), errors (2). Redirection (
>,>>,2>) and pipes (|) compose commands into pipelines.
Scheduling: run it on time, every time
- cron — the time-based scheduler: five fields (minute, hour, day-of-month, month, day-of-week) plus the command.
0 2 * * *= 2 AM daily. Per-user crontabs plus system cron directories. - at — run once at a specified time. The "remind me later" to cron's "every day."
- systemd timers — the modern alternative: timer units triggering service units, with journal-integrated logging and calendar or monotonic (e.g., "hourly") schedules.
- What to watch — cron jobs need full paths and explicit environment (cron's PATH is minimal); scripts must be idempotent (safe to run twice) because schedules will overlap eventually.
*/15 * * * * = every 15 minutes.Orchestration: from one machine to a fleet
- Configuration management — tools (Ansible, Puppet, Chef) enforce a declared desired state across many machines: "all web servers have this package and this config." Idempotent by design.
- Ansible concepts — agentless (SSH, no client to install), YAML playbooks describing tasks, inventory listing target hosts. Focus on the model, not playbook syntax mastery.
- Version control for infrastructure — scripts and playbooks live in git: reviewed, tested, rolled back like code. "Infrastructure as code" means the automation is the documentation.
- CI/CD pipelines (concept) — automate the path from commit to deployment: test the script, then run it everywhere. The exam touches this as the destination that scripting enables.
The must-memorize table: scheduling tools
Which scheduler for which need.
| Tool | Runs | Best for |
|---|---|---|
| cron | Recurring, on a calendar schedule | Nightly backups, log rotation, daily reports |
| at | Once, at a set time | One-off delayed tasks |
| systemd timer | Recurring, with dependency handling | Modern distros; needs logging/monitoring integration |
| sleep + script loop | continuously while running | Almost never — fragile, no boot persistence |
Try it: 4 sample questions
Sample questions to check your understanding of this domain. Answers and full reasoning are tucked under each one.
1. A script must back up a database every night at 2:30 AM. Which cron entry is correct?
- A. A. 30 2 * * * /usr/local/bin/db-backup.sh
- B. B. 2 30 * * * /usr/local/bin/db-backup.sh
- C. C. * * 2 30 * /usr/local/bin/db-backup.sh
- D. D. 0 0 30 2 * /usr/local/bin/db-backup.sh
Show answer & reasoning
A. Cron fields are minute, hour, day-of-month, month, day-of-week: 30 minutes past 2 AM, every day = 30 2 * * *. (B) swaps minute and hour (2:30 AM vs. 30:02 — invalid); (C) and (D) put the numbers in the wrong fields entirely. Read left to right, five fields.
2. Inside double quotes, "$HOME" expands to the home directory. Inside single quotes it stays literal. What is this distinction called, and why does it matter?
- A. A. Globbing — it controls filename expansion
- B. B. Quoting — it controls whether the shell interprets special characters
- C. C. Redirection — it controls output streams
- D. D. Piping — it connects commands
Show answer & reasoning
B. Quoting controls interpretation: double quotes allow $ expansion; single quotes suppress it. Scripts break mysteriously when a variable that should expand doesn't (or vice versa) — this is the #1 beginner scripting bug — verify your quoting.
3. A deployment script must be safe to run twice in a row without duplicating its effects. What property is this?
- A. A. Elasticity
- B. B. Idempotence
- C. C. Volatility
- D. D. Parallelism
Show answer & reasoning
B. Idempotence: running it N times has the same effect as running it once. Schedules overlap, playbooks re-run, humans double-click — automation that isn't idempotent eventually corrupts state. It's the defining property of reliable configuration management.
4. A company manages 200 web servers and wants the same Apache configuration enforced on all of them automatically. Which approach fits?
- A. A. SSH into each server and edit the config by hand
- B. B. A configuration management tool declaring the desired state
- C. C. A cron job that emails the admin daily
- D. D. A longer sudo timeout
Show answer & reasoning
B. Declared desired state, enforced everywhere identically and continuously — that's configuration management (Ansible/Puppet/Chef). Manual edits (A) guarantee drift across 200 machines; cron emails (C) only report; the goal is enforcement, not notification.
This was one domain. The simulator drills all 5.
This free preview covered Automation, Orchestration & Scripting (Domain 4.0, 17%). Not covered here: Security (Domain 3.0, 18%); Troubleshooting (Domain 5.0, 22%). Linux security hardening and scenario troubleshooting stay in the paid guide and practice bank. The ByteBar Practice Exam Simulator drills every domain with 1,000 exam-style questions — $9.99 one-time unlocks all 28 exams. Prefer to read? The full Linux+ Study Guide is in the ByteBar shop on Etsy.
Practice Exam Simulator — $9.99 one-time, all 28 exams Full Study Guides on Etsy