· about 30 minutes · runs on ubuntu-26.04-devops · unrated
An unrated lab. It runs on your machine with no account and no network, and everything about it — the faults, the checks, the hints and the reference solution — is in the repository. An attempt on it is recorded on your profile and never moves a rating: only rated labs do. Rated and unrated labs.
errors-report reads the shop's access log, /var/log/shop/access.log, and writes the server errors
(status 500–599) per endpoint to /var/lib/shop/errors.txt for the morning stand-up.
errors-report.timer runs it shortly after boot and every night.
Somebody added set -euo pipefail after a code review. Since then the timer's run fails on every
good night — the nights with no errors at all — and the alert about the failed unit has been
muted. On bad nights the report shows /cart twice with two different counts.
What is expected, and graded — the grader runs errors-report itself, through the LOG and
REPORT variables the script already reads. The report is one line per endpoint, <count> <path>,
highest count first (equal counts by path), then a last line total <N>:
total 0, and the script exits 0.errors-report.timer succeeds and writes the report — and still does after a
reboot.You have root through sudo.
The machine is checked, rebooted, and checked again. A check passes only if it passes both times.
| Check | Objective |
|---|---|
| 01_a_quiet_night_is_a_report | Tell 'nothing matched' from 'something failed' in a pipeline under set -e and pipefail |
| 02_counts_are_per_endpoint | Count occurrences correctly with sort and uniq |
| 03_a_missing_log_is_an_error | Tell 'nothing matched' from 'something failed' in a pipeline under set -e and pipefail |
| 04_the_nightly_run_succeeds | Run a report from a systemd timer and prove the run succeeded |
Where the lab's hints send you, level by level, as you ask for them (h, then l opens a journal section in the TUI).
man 1 grepman 1 uniqman 1 sortman 1 bashman 5 systemd.serviceman 1 journalctl4 questions on the same topic, in the lab's Theory tab. They never affect the lab's grade. Three of them, to answer here:
What does this print?
grep nosuchuser /etc/passwd
echo "status=$?"
status=1
grep exits 1 when no line matched, 0 when at least one did, and 2 when it could not do its job (an unreadable file, a bad pattern). "Nothing matched" is an answer, which is why if grep -q works; under set -e with pipefail that same 1 stops a script.
man 1 grep (EXIT STATUS) · executed in a sandbox
What does this print?
out=$(bash -c 'set -euo pipefail; grep zz /etc/hostname | wc -l; echo next')
echo "$out status=$?"
0 status=1
wc -l runs and prints 0, so the pipeline's last command succeeds; pipefail makes the pipeline's status grep's 1, and set -e ends the script before echo next. Without pipefail the pipeline would have been successful and next would have been printed.
man 1 bash (set -e, pipefail) · executed in a sandbox
What does this print?
printf 'b\na\nb\n' | uniq -c | awk '{ printf "%s %s ", $1, $2 }'
1 b 1 a 1 b
uniq compares each line only with the one before it, so the two b lines are never adjacent and are counted separately. Sorting first — sort | uniq -c — is what turns this into occurrence counts. (The awk is only there to put the three pairs on one line.)
man 1 uniq · man 1 sort · executed in a sandbox