Skip to content
Hands-on IT IT Drills

Appendix B: Final Exam

Goal: Prove that you master the shell, tmux, editor, Git, SSH and dotfiles without a mouse and without looking things up in the chapters. · Duration: 120 min practical + 20 min questions · Prerequisite: Day 15

Rules

  • Everything runs in the practice home ~/term-lab with the lab shell (~/term-lab/lab), the lab tmux (tl), the lab gitconfig and the lab kubeconfig. Your real dotfiles stay untouched.
  • Allowed: Appendix A, man, tldr, <tool> --help. Not allowed: copying solutions from the chapters.
  • Each task earns 10 points, but only if all its checks in the check script show ✔.
  • Passed: at least 70 of 100 points and Task 9 (new Mac) solved.
  • Tested on macOS 15.6.1 with the versions from Appendix A. Outputs may differ slightly under macOS 26.

Preparation

The exam needs a few files from Day 15. If logs/app.jsonl or ~/term-lab/wk/dotfiles is missing, repeat the preparation there. Then the exam ground:

mkdir -p ~/term-lab/pruefung/repo ~/term-lab/pruefung/neu/home
cd ~/term-lab/pruefung
printf 'web-01\nweb-02\ndb-01\ncache-01\n' > hosts.txt
cd repo && git init -q
printf 'def total(items):\n    return sum(items)\n' > shop.py
git add . && git commit -qm "feat: total"
echo "# Doku" > README.md && git add . && git commit -qm "docs: README"
echo "VERSION = '1.0'" > version.py && git add . && git commit -qm "chore: version"
/usr/sbin/sshd -f ~/term-lab/ssh/sshd_config -E ~/term-lab/ssh/sshd.log
git ll

Expected (hashes will differ):

e408cc2 chore: version
1a134df docs: README
63b4734 feat: total

If the practice sshd is already running, the sshd call reports Address already in use. That’s fine.

Part 1: Practical exam

Task 1: Shell (10 points)

The lab zsh runs in Emacs mode, ⌃R opens fzf, ⌥R atuin, ↑ searches by prefix, and a startup takes less than 100 ms. Hint: Day 2 to 4.

Task 2: Function logerr (10 points)

In ~/term-lab/config/zsh/pruefung.zsh, write a function logerr [datei]. It counts the ERROR lines per component (2nd column), sorted in descending order, default file logs/app.log. If the file isn’t readable: message on stderr and exit code 2.

logerr ~/term-lab/projekt/logs/app.log
logerr /gibtsnicht; echo "rc=$?"

Expected:

     50 checkout
logerr: '/gibtsnicht' nicht lesbar
rc=2

Task 3: Script jsonerr (10 points)

~/term-lab/bin/jsonerr <user> [datei] is a Bash script with set -euo pipefail. It outputs the request IDs of all of the user’s ERRORs from logs/app.jsonl, comma-separated, is shellcheck-clean and aborts with an error when no user is given.

cd ~/term-lab/projekt && jsonerr u06

Expected:

r0006,r0236,r0466

Task 4: tmux session pruefung (10 points)

On the lab server, the session pruefung runs with two windows: code with two panes side by side and logs, in which tail -f logs/app.log is running. Hint: Day 8, 9 and 15.

Task 5: Repairing an old commit (10 points)

In the repo ~/term-lab/pruefung/repo, total gets the line """Summe aller Positionen.""" as its docstring, in the commit feat: total. Afterwards the history still has exactly three commits, no fixup! and a clean working tree. Hint: the target is the repo’s first commit.

Task 6: Neovim (10 points)

Using nv, turn ~/term-lab/pruefung/hosts.txt into the file hosts.yaml:

hosts:
  - name: web-01
  - name: web-02
  - name: db-01
  - name: cache-01

No retyping of the host names. hosts.txt stays unchanged.

Task 7: jq and yq (10 points)

Create ~/term-lab/pruefung/report.json with four fields: errors and warns (counts from logs/app.jsonl), image and replicas (from deploy/k8s/deployment.yaml). Numbers as numbers, not as strings.

jq -c . ~/term-lab/pruefung/report.json

Expected:

{"errors":50,"warns":50,"image":"ghcr.io/example/shop:1.4.2","replicas":3}

Task 8: SSH (10 points)

Add a host pruefung-app to ~/term-lab/ssh/config: 127.0.0.1, port 2222, lab key, reachable only via lab-bastion, and with its own connection instead of the shared master socket. lssh pruefung-app true works without a prompt. Hint: Day 12.

Task 9: New Mac (10 points, mandatory)

In one command, bring the dotfiles repo ~/term-lab/wk/dotfiles into the empty home ~/term-lab/pruefung/neu/home, this time for a work machine (work, email [email protected]). Source, configuration, state and cache live under ~/term-lab/pruefung/neu/{src,cfg}. Don’t run any scripts. Hint: Day 13 and Drill 10 from Day 15.

Task 10: Kubernetes, safely (10 points)

In the lab kubeconfig, kind-lab is active, with namespace shop. The prod guard from k8s.zsh also asks for kubectl exec and can be turned off for scripts with KUBECTL_PROD_OK=1. Hint: Day 14 with its challenge.

Check script

cat > ~/term-lab/pruefung/check.zsh <<'EOF'
#!/usr/bin/env zsh
# check.zsh – check script for Appendix B. Usage: zsh ~/term-lab/pruefung/check.zsh
LAB=${LAB:-~/term-lab}; P=$LAB/projekt; PR=$LAB/pruefung; N=$PR/neu
summe=0 fehler=0 pflicht=0
ok() {
  local m=$1; shift
  if "$@" >/dev/null 2>&1; then print "  ✔ $m"; else print "  ✘ $m"; fehler=1; fi
}
aufgabe() { print "Aufgabe $1: $2"; fehler=0; }
punkte()  { (( fehler )) || (( summe += 10 )); }
lab()     { (cd $P && env ZDOTDIR=$LAB/zsh zsh -i -c "$1" 2>/dev/null); }
tl()      { tmux -L lab -f $LAB/tmux.conf "$@" 2>/dev/null; }
lssh()    { ssh -F $LAB/ssh/config -o BatchMode=yes "$@"; }
czp() {
  chezmoi --source $N/src --destination $N/home --config $N/cfg/chezmoi.toml \
    --persistent-state $N/cfg/state.boltdb --cache $N/cfg/cache "$@"
}

aufgabe 1 "Shell"
ok "Emacs-Modus"          test "$(lab 'bindkey -lL main')" = "bindkey -A emacs main"
ok "⌃R fzf, ⌥R atuin"     lab '[[ $(bindkey "^R") == *fzf-history-widget &&
                                $(bindkey "^[r") == *atuin-search ]]'
ok "↑ mit Präfix"         lab '[[ $(bindkey "^[[A") == *beginning-search ]]'
ok "Start unter 100 ms"   lab 'zmodload zsh/datetime; s=$EPOCHREALTIME
                               repeat 10 { zsh -i -c exit }
                               (( (EPOCHREALTIME - s) * 100 < 100 ))'
punkte

aufgabe 2 "Funktion logerr"
ok "zählt pro Komponente" lab "[[ \$(logerr $P/logs/app.log) == *'50 checkout' ]]"
ok "Exit-Code 2"          lab 'logerr /gibtsnicht; (( $? == 2 ))'
punkte

aufgabe 3 "Skript jsonerr"
ok "shellcheck sauber"    shellcheck $LAB/bin/jsonerr
ok "IDs von u06"          test "$($LAB/bin/jsonerr u06 $P/logs/app.jsonl)" \
                            = r0006,r0236,r0466
ok "ohne User: Fehler"    sh -c "! $LAB/bin/jsonerr"
punkte

aufgabe 4 "tmux-Session pruefung"
ok "Fenster code, logs"   test "$(tl list-windows -t pruefung -F '#W' | xargs)" \
                            = "code logs"
ok "code: zwei Panes"     test "$(tl display -p -t pruefung:code '#{window_panes}')" = 2
ok "logs: tail läuft"     test \
  "$(tl display -p -t pruefung:logs '#{pane_current_command}')" = tail
punkte

aufgabe 5 "Git: alter Commit repariert"
ok "drei Commits"         test "$(git -C $PR/repo rev-list --count HEAD)" = 3
ok "Docstring im ersten"  sh -c "git -C $PR/repo show HEAD~2:shop.py |
                                 grep -q 'Summe aller Positionen'"
ok "kein fixup! übrig"    sh -c "! git -C $PR/repo log --format=%s | grep -q '^fixup!'"
ok "Arbeitsbaum sauber"   test -z "$(git -C $PR/repo status --porcelain)"
punkte

aufgabe 6 "Neovim: hosts.yaml"
ok "Kopfzeile hosts:"     test "$(head -1 $PR/hosts.yaml)" = "hosts:"
ok "vier Einträge"        test "$(yq '.hosts | length' $PR/hosts.yaml)" = 4
ok "dritter ist db-01"    test "$(yq '.hosts[2].name' $PR/hosts.yaml)" = db-01
punkte

aufgabe 7 "jq/yq: report.json"
ok "Werte stimmen"        jq -e '.errors == 50 and .warns == 50 and .replicas == 3
                            and (.image | endswith(":1.4.2"))' $PR/report.json
punkte

aufgabe 8 "SSH: pruefung-app"
ok "ProxyJump lab-bastion" sh -c "ssh -F $LAB/ssh/config -G pruefung-app |
                                  grep -qx 'proxyjump lab-bastion'"
ok "eigene Verbindung"    sh -c "! ssh -F $LAB/ssh/config -G pruefung-app |
                                 grep -q '^controlpath '"
ok "Login klappt"         lssh pruefung-app true
punkte

aufgabe 9 "Neuer Mac (Pflicht)"
ok "Kunden-Datei da"      test -f $N/home/.config/kunde/kunde.zsh
ok "Proxy in .gitconfig"  grep -q proxy.kunde.example $N/home/.gitconfig
ok "secrets.env 0600"     test \
  "$(stat -f %Lp $N/home/.config/termlab/secrets.env)" = 600
ok "keine Drift"          test -z "$(czp status | grep '^.M')"
punkte; (( fehler )) || pflicht=1

aufgabe 10 "Kubernetes sicher"
KC=$PR/kc-test; cp $LAB/kube/config $KC
command kubectl --kubeconfig $KC config use-context kunde-prod >/dev/null
ok "Lab-Kontext kind-lab" test "$(kubectl --kubeconfig $LAB/kube/config \
                            config current-context)" = kind-lab
ok "Namespace shop"       test "$(kubectl --kubeconfig $LAB/kube/config \
                            config view --minify -o jsonpath='{..namespace}')" = shop
ok "Wächter stoppt exec"  lab "[[ \$(KUBECONFIG=$KC kubectl exec web-1 -- id \
                            2>&1 </dev/null) == *ACHTUNG* ]]"
ok "KUBECTL_PROD_OK=1"    lab "[[ \$(KUBECONFIG=$KC KUBECTL_PROD_OK=1 kubectl exec \
                            --request-timeout=1s web-1 -- id 2>&1) != *ACHTUNG* ]]"
rm -f -- $KC
punkte

print "Summe: $summe von 100 Punkten"
(( summe >= 70 && pflicht )) && print "✔ bestanden" || print "✘ nicht bestanden"
EOF
zsh ~/term-lab/pruefung/check.zsh

Expected (everything solved, shortened):

Aufgabe 1: Shell
  ✔ Emacs-Modus
  ✔ ⌃R fzf, ⌥R atuin
  ✔ ↑ mit Präfix
  ✔ Start unter 100 ms
...
Aufgabe 10: Kubernetes sicher
  ✔ Lab-Kontext kind-lab
  ✔ Namespace shop
  ✔ Wächter stoppt exec
  ✔ KUBECTL_PROD_OK=1
Summe: 100 von 100 Punkten
✔ bestanden

The script only touches lab files. For the guard test, it works on a copy of the lab kubeconfig (kc-test) and deletes it afterwards. The client clusters are made up, so the permitted exec ends with a connection error. That’s intended.

Points

Task Points achieved
1 Shell 10
2 Function logerr 10
3 Script jsonerr 10
4 tmux session 10
5 Old commit 10
6 Neovim 10
7 jq and yq 10
8 SSH 10
9 New Mac (mandatory) 10
10 Kubernetes, safely 10
Total 100

Solution sketches

Only read these once the check script has run.

# 2 – in ~/term-lab/config/zsh/pruefung.zsh, then reload
logerr() {
  local f=${1:-logs/app.log}
  [[ -r $f ]] || { print -u2 "logerr: '$f' nicht lesbar"; return 2; }
  awk '$3 == "ERROR" { n[$2]++ } END { for (m in n) printf "%7d %s\n", n[m], m }' "$f" |
    sort -rn
}
# 3 – ~/term-lab/bin/jsonerr, then chmod +x
#!/usr/bin/env bash
set -euo pipefail
user="${1:?usage: jsonerr <user> [datei]}"
file="${2:-logs/app.jsonl}"
jq -r --arg u "$user" 'select(.level == "ERROR" and .user == $u) | .req' "$file" |
  paste -sd, -
# 4 – in the project folder, outside tmux
tl new -s pruefung -n code \; split-window -h \; new-window -n logs \; \
  send-keys 'tail -f logs/app.log' Enter
# 5 – add the docstring to shop.py (nv), then
git add shop.py && git fixup ":/feat: total"
GIT_SEQUENCE_EDITOR=: git ri --root
# 7
D=deploy/k8s/deployment.yaml
jq -n --slurpfile log logs/app.jsonl \
  --arg image "$(yq '.spec.template.spec.containers[0].image' $D)" \
  --argjson replicas "$(yq '.spec.replicas' $D)" \
  '{errors: ([$log[] | select(.level == "ERROR")] | length),
    warns:  ([$log[] | select(.level == "WARN")] | length),
    image: $image, replicas: $replicas}' > ~/term-lab/pruefung/report.json
# 9 – function like czneu from Day 15, just with $LAB/pruefung/neu
N=~/term-lab/pruefung/neu
chezmoi --source $N/src --destination $N/home --config $N/cfg/chezmoi.toml \
  --persistent-state $N/cfg/state.boltdb --cache $N/cfg/cache \
  init --apply --exclude=scripts --promptChoice Rechnerart=work \
  --promptString [email protected] ~/term-lab/wk/dotfiles
# 10
kubectl config use-context kind-lab
kubectl config set-context --current --namespace=shop

On 1: Day 2 to 4 provide all the building blocks; compinit -C from the Day 2 challenge brings down the startup time. On 5: the target is the first commit, so there’s no HEAD~3. --root takes the whole history into the todo list. On 6 in nv: :%s/^/ - name: /, then :0put ='hosts:' and :w hosts.yaml, finally :q! so that hosts.txt stays unchanged. A macro from Day 11 works just as well. On 8: the block from Day 12 (lab-app) plus ControlPath none, inserted before Host *. On 10: the solution to the Day 14 challenge.

Part 2: Short questions

1 point each, pass mark 18 of 25. Answer in one sentence.

  1. Why doesn’t a PATH change belong in .zshenv on the Mac?
  2. Which startup files does an interactive login zsh read, and in what order?
  3. Why does ⌃A suddenly stop working when EDITOR=nvim is set?
  4. What’s the difference between ⌃U and ⌃K in the lab configuration?
  5. What is ⌥Q for, and when does the line come back?
  6. What do !$ and ⌥. return, and how do they differ?
  7. How do you keep a command with a token out of the history, and why isn’t that a vault?
  8. When do you use an alias, when a function, when a script?
  9. Why does rg ERROR find nothing in logs/ in the practice project, and how do you search there anyway?
  10. What do 'cart, ^config, .yaml$ and !deploy mean in fzf?
  11. In the lab, which keys belong to fzf, which to atuin, which to the prefix search?
  12. What happens to a tmux session when you close the terminal window?
  13. Why does the lab use tmux -L lab -f … everywhere?
  14. In nested tmux, how do you address the inner one when both have the prefix ⌃a?
  15. What does set -sg escape-time 10 do, and why does Neovim need it?
  16. What do git fixup ":/feat: sub" and then git ri main do?
  17. What side effect does rebase.updateRefs = true have, and how do you prevent it once?
  18. What are worktrees for, and where is their limit?
  19. What does ciw do, and why is it usually better than dw plus i?
  20. How do you replace match by match with control in Neovim, without :s?
  21. Why is ProxyJump safer than ForwardAgent yes?
  22. What does ControlMaster save, and why does %C belong in the ControlPath?
  23. How does a secret get into a chezmoi file without landing in the repo?
  24. What does direnv allow do, and why do you have to repeat it after changes?
  25. Why doesn’t the prod guard in k8s.zsh replace RBAC?

Answer key

  1. /etc/zprofile runs after .zshenv and, via path_helper, puts the system paths at the front, so Homebrew slips to the back (Day 2).
  2. .zshenv, .zprofile, .zshrc, .zlogin, each after the system variant from /etc (Day 2).
  3. If $EDITOR or $VISUAL contains “vi”, zsh switches to vi mode; bindkey -e forces Emacs keys (Day 3).
  4. ⌃U deletes everything left of the cursor (backward-kill-line), ⌃K everything to the right (Day 3).
  5. It parks the current line; after the next executed command, it’s back at the prompt (Day 3).
  6. Both return the last word of the previous command; !$ is expanded on execution, ⌥. inserts it immediately and visibly and goes further back when repeated (Day 3).
  7. With a leading space, thanks to HIST_IGNORE_SPACE; but the command stays briefly retrievable via ↑ and is visible in the process list (Day 4).
  8. Alias for plain abbreviations, function for arguments, logic or cd, script when other programs should call it or another language is needed (Day 5).
  9. logs/ is in .gitignore, and rg respects that; use rg -u, rg -uu or the explicit path rg ERROR logs (Day 6).
  10. Exact match, starts with, ends with, doesn’t contain (Day 7).
  11. ⌃R fzf history, ⌥R atuin, ↑ prefix search; plus ⌃T and ⌥C for fzf files and folders (Day 4, 7).
  12. It keeps running in the tmux server and can be brought back with tmux attach (Day 8).
  13. Its own socket and its own configuration, so the lab touches neither an existing tmux nor ~/.tmux.conf (Day 8).
  14. Prefix twice: the outer tmux catches the first ⌃a, send-prefix sends the second one inside; alternatively F12 (Day 9).
  15. After Esc, tmux waits only 10 ms for further characters; otherwise Esc reaches Neovim with a noticeable delay (Day 8).
  16. A fixup! commit for the youngest commit with a matching message; then the interactive rebase sorts it behind its target and folds it in (Day 10).
  17. The rebase moves along every branch that points to a rewritten commit, such as main; turn it off once with git rebase --no-update-refs (Day 15).
  18. Several branches checked out at the same time without stash; but a branch can only be checked out in one worktree (Day 10).
  19. It replaces the whole word under the cursor, no matter where in it the cursor is, and can be repeated with . (Day 11).
  20. Set the word as the search pattern with *, cgn changes the next match, . repeats, n skips (Day 11).
  21. With agent forwarding, root on the bastion can use your agent; ProxyJump only passes encrypted bytes through (Day 12).
  22. The connection setup for every further session over the same socket; %C is a short hash of host, port and user, because Unix sockets only tolerate about 100 characters (Day 12).
  23. Via a template that fetches the secret on apply from 1Password (onepasswordRead) or the keychain (keyring), plus private_ for 0600 permissions (Day 13).
  24. It approves exactly this content of the .envrc for execution; every change blocks it, so a foreign git pull can’t slip anything in (Day 14).
  25. It’s convenience in your own shell and can be bypassed with command kubectl; real boundaries are drawn by RBAC, admission policies and GitOps (Day 14).

Part 3: Self-assessment

Topic I can do it done in the lab
Practice home, Brewfile, Nerd Font (Day 0) [ ] [ ]
Terminal app, Option as Meta, splits (Day 1) [ ] [ ]
Startup files, PATH, completion, startup time (Day 2) [ ] [ ]
Editing the command line, expansion, globs (Day 3) [ ] [ ]
History, fzf ⌃R, atuin (Day 4) [ ] [ ]
Aliases, functions, scripts (Day 5) [ ] [ ]
rg, fd, bat, eza, zoxide, jq, yq, delta (Day 6) [ ] [ ]
fzf and your own pickers (Day 7) [ ] [ ]
tmux: sessions, panes, copy mode (Day 8) [ ] [ ]
tmux: projects, popups, persistence, SSH (Day 9) [ ] [ ]
Git: switch/restore, add -p, fixup, worktrees, bisect (Day 10) [ ] [ ]
Neovim: motions, text objects, macros, quickfix (Day 11) [ ] [ ]
SSH config, ControlMaster, ProxyJump, macOS commands (Day 12) [ ] [ ]
chezmoi, Brewfile, defaults, bootstrap (Day 13) [ ] [ ]
direnv, mise, make/just, kubectx, prod guard (Day 14) [ ] [ ]
Speed drills in pro time (Day 15) [ ] [ ]

Every row without two checkmarks: work through that chapter again. Then repeat the competition from Day 15 and compare with wkstand.

Clean up after the exam: tl kill-session -t pruefung and kill "$(cat ~/term-lab/ssh/sshd.pid)". You can first look at the folder ~/term-lab/pruefung with echo rm -rf ~/term-lab/pruefung and then delete it without echo (Day 0).