· 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.
backup-docs copies every file under /srv/docs into /var/backups/docs/<YYYY-MM-DD>/, keeping the
relative paths. backup-docs.timer runs it shortly after boot and every night.
Last week legal asked for last month's contract, Contract - ACME.pdf. It was not in any backup.
The job's journal says backed up 0 files every night, systemd lists every run as successful, and
nobody had looked at it since it was written.
What is expected, and graded — the grader runs backup-docs itself, as an ordinary user, against its
own directories, through the DOCS_DIR and BACKUP_DIR variables the script already reads:
backed up N files, where N is the number of files it copied.backup-docs.timer succeeds and backs up everything in /srv/docs — 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_every_file_is_copied | Walk a directory tree in a shell script without breaking on any file name |
| 02_the_count_is_true | Keep a count across a loop, and report failures with an exit status |
| 03_a_failed_copy_is_reported | Keep a count across a loop, and report failures with an exit status |
| 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 findman 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:
What does this print?
count=0
printf 'a\nb\nc\n' | while read -r line; do count=$((count + 1)); done
echo "$count"
0
The while loop is the second command of a pipeline, so bash runs it in a subshell. The loop increments that subshell's copy of count, which disappears when the loop ends; the parent still has 0. It would be 3 with the loop fed by a redirection, done < <(printf ...), or with shopt -s lastpipe in a non-interactive shell.
man 1 bash (Pipelines; COMMAND EXECUTION ENVIRONMENT) · executed in a sandbox
What does this print?
printf '%s\n' 'Q3\forecast.csv' | while read f; do echo "$f"; done
Q3forecast.csv
Without -r, read treats a backslash as an escape character and removes it, so the name loses its backslash before the loop body sees it. read -r keeps backslashes as ordinary characters, which is what any loop over file names needs.
man 1 bash (SHELL BUILTIN COMMANDS: read) · executed in a sandbox
A loop reads file names with `find "$dir" -type f | while read f`. Which of these names can reach the loop body changed or split? Select all that apply.
a name containing a backslash, a name containing a newline, a name that ends with a space — more than one answer
find separates names with newlines, so a newline splits one name into two lines. read strips leading and trailing IFS whitespace from the line; find prints the whole path, so a trailing space in the name is lost, while blanks at the start of the last component survive because they are not at the start of the line. Without -r read also removes backslashes. A single space in the middle survives read — it is broken later, by an unquoted expansion. The safe form is find -print0 with while IFS= read -r -d ''.
man 1 find (-print0) · man 1 bash (SHELL BUILTIN COMMANDS: read)