· 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.
/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:
env -i, apart from those two variables), it writes the
report and exits 0.REPORT_OUT set, it reads the default
configuration and writes the report.nightly-report.timer succeeds and writes a report of every project — 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_runs_with_an_empty_environment | Write a script that does not depend on the caller's environment or working directory |
| 02_runs_from_any_directory | Write a script that does not depend on the caller's environment or working directory |
| 03_missing_config_fails_cleanly | Fail a script, and keep the previous output, when its input is missing |
| 04_the_nightly_run_succeeds | Run a script 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 envman 5 systemd.execman 1 bashman 5 systemd.serviceman 5 systemd.timer4 questions on the same topic, in the lab's Theory tab. They never affect the lab's grade. Three of them, to answer here:
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?
an interactive shell after sudo -i
Only an interactive shell reads ~/.bashrc (a login shell reaches it through ~/.profile), and Ubuntu's .bashrc returns straight away in a non-interactive shell, before the appended line. systemd, cron and bash -c start without an interactive shell, so they never see it.
man 1 bash (INVOCATION)
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'
from-a
For a name without a slash, the . builtin searches the directories in PATH before the current directory, so /tmp/a/conf is found first even though the shell is in /tmp/b. Sourcing a configuration by a bare name therefore depends on both PATH and the working directory; an absolute path depends on neither.
man 1 bash (SHELL BUILTIN COMMANDS: . filename) · executed in a sandbox
What does this print?
echo old > /tmp/report.txt
{ echo new; false; } > /tmp/report.txt || true
cat /tmp/report.txt
new
The redirection opens and truncates /tmp/report.txt before the group runs, so the old content is gone whatever happens next; the group writes new and then fails. Write to a temporary file and rename it over the report only on success to keep the previous version.
man 1 bash (REDIRECTION) · executed in a sandbox