[ norboten ]
bash · lab bash-04

The Job That Works Only by Hand

· 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

/opt/reports/bin/nightly-report writes the disk use of every project listed in /opt/reports/report.conf to /var/lib/reports/latest.txt, which the morning mail attaches. nightly-report.timer runs it shortly after boot and every night.

The mail has attached an empty report for a week. Whenever someone logs in with sudo -i and runs the script by hand, it works and prints report written. systemd lists every timer run as successful anyway.

What is expected, and graded — the grader runs the script itself, through the REPORT_CONF (the configuration, default /opt/reports/report.conf) and REPORT_OUT (the report, default /var/lib/reports/latest.txt) variables the script already reads:

  1. Started with an empty environment (env -i, apart from those two variables), it writes the report and exits 0.
  2. Started from any working directory, with only REPORT_OUT set, it reads the default configuration and writes the report.
  3. When the configuration file does not exist, it exits non-zero and the previous report is left exactly as it was.
  4. The run started by nightly-report.timer succeeds and writes a report of every project — 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_runs_with_an_empty_environmentWrite a script that does not depend on the caller's environment or working directory
02_runs_from_any_directoryWrite a script that does not depend on the caller's environment or working directory
03_missing_config_fails_cleanlyFail a script, and keep the previous output, when its input is missing
04_the_nightly_run_succeedsRun a script from a systemd timer and prove the run succeeded

Start it

  1. 2Labs
  2. bash-04select 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

A line `export PATH="$PATH:/opt/tools/bin"` is appended to the end of root's Ubuntu-default `~/.bashrc`. In which of these does a command from `/opt/tools/bin` resolve?

Question 2

What does this print?

mkdir -p /tmp/a /tmp/b
echo 'echo from-a' > /tmp/a/conf
echo 'echo from-b' > /tmp/b/conf
cd /tmp/b
PATH=/tmp/a:$PATH bash -c '. conf'
Question 3

What does this print?

echo old > /tmp/report.txt
{ echo new; false; } > /tmp/report.txt || true
cat /tmp/report.txt