[ norboten ]
bash · lab bash-06

The Report That Dies on a Quiet Night

· 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.

The briefing

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>:

  1. A log with no server errors produces a report of just total 0, and the script exits 0.
  2. A log with errors produces one line per endpoint with the right counts, in that order.
  3. A log that does not exist, or cannot be read, makes the script exit non-zero with a message on standard error.
  4. The run started by errors-report.timer succeeds and writes the report — and still does after a reboot.

You have root through sudo.

What is graded

The machine is checked, rebooted, and checked again. A check passes only if it passes both times.

CheckObjective
01_a_quiet_night_is_a_reportTell 'nothing matched' from 'something failed' in a pipeline under set -e and pipefail
02_counts_are_per_endpointCount occurrences correctly with sort and uniq
03_a_missing_log_is_an_errorTell 'nothing matched' from 'something failed' in a pipeline under set -e and pipefail
04_the_nightly_run_succeedsRun a report from a systemd timer and prove the run succeeded

Start it

  1. 2Labs
  2. bash-06select this one
  3. udownload it
  4. sstart the machine

Reading

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).

Theory for this lab

4 questions on the same topic, in the lab's Theory tab. They never affect the lab's grade. Three of them, to answer here:

Question 1

What does this print?

grep nosuchuser /etc/passwd
echo "status=$?"
Question 2

What does this print?

out=$(bash -c 'set -euo pipefail; grep zz /etc/hostname | wc -l; echo next')
echo "$out status=$?"
Question 3

What does this print?

printf 'b\na\nb\n' | uniq -c | awk '{ printf "%s %s ", $1, $2 }'