04 / RELIABLE ADMINISTRATION TOOLS · LESSON 16

Publish a daily operations report

Write deterministic reports and distinguish review findings from unknown observations.

16 min · learn at your pace

A daily report needs stable meaning

A fleet summary should separate items needing review from items that could not be assessed. Combining unknown observations with healthy ones makes a quiet report look more reassuring than the evidence supports. Keep the states explicit and count them independently.

The input contains already validated review rows with unique asset/category pairs. Sort by asset and category under LC_ALL=C so the same input produces the same bytes regardless of input order. Count distinct asset IDs separately from review rows; one asset may have several categories.

Publish complete outputs

Check that the required input exists before changing earlier reports. Build the report and summary in a private temporary directory, then move the completed files to the output directory. Successful reruns replace earlier outputs rather than accumulating another copy of every row.

This staging protects against ordinary processing failures before publication; moving multiple files is not an atomic transaction across the directory. A production service needing a single publication boundary could use versioned directories and a manifest pointer. In this lab, the guarantee is precise: missing input leaves old reports intact, repeated successful runs are deterministic, and source evidence never changes.

Try an example.sh
awk -F '\t' 'NR>1 {n[$3]++} END {printf "review=%d unknown=%d\n",n["review"],n["unknown"]}' reviews.tsv
YOUR TURN

Put it into practice.

Accept an optional output directory, default reports. Required reviews.tsv has validated unique asset_id<TAB>category<TAB>state<TAB>detail rows, with state ok, review or unknown. Write report.tsv with the same header, sorted by asset then category in LC_ALL=C order. Write summary.txt with assets=N (distinct IDs), rows=N, ok=N, review=N and unknown=N, in that order with final newlines. Missing input fails nonzero with Missing reviews on stderr before changing previous reports. Repeated successful runs replace outputs and preserve the input; output paths may contain spaces.

See an explained solution
One way to solve it.sh
export LC_ALL=C
out=${1:-reports}
[ -f reviews.tsv ] || { printf 'Missing reviews\n' >&2;exit 1; }
tmp=$(mktemp -d "${TMPDIR:-/tmp}/rocks-daily.XXXXXX") || exit 1
trap 'rm -rf "$tmp"' EXIT
printf 'asset_id\tcategory\tstate\tdetail\n' > "$tmp/report.tsv"
awk 'NR>1' reviews.tsv | sort -t $'\t' -k1,1 -k2,2 >> "$tmp/report.tsv" || exit 1
awk -F '\t' 'NR>1 {assets[$1]=1;rows++;counts[$3]++} END {for(a in assets)n++;printf "assets=%d\nrows=%d\nok=%d\nreview=%d\nunknown=%d\n",n,rows,counts["ok"],counts["review"],counts["unknown"]}' reviews.tsv > "$tmp/summary.txt" || exit 1
mkdir -p "$out" || exit 1
mv "$tmp/report.tsv" "$out/report.tsv" || exit 1
mv "$tmp/summary.txt" "$out/summary.txt"

The report preserves category-level detail while the summary distinguishes coverage gaps from actual review findings. Explicit sorting and derived counts make reruns reproducible, and a required-input guard protects previous reports from an incomplete collection.