· about 40 minutes · runs on ubuntu-26.04, alpine · 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.
Operations wants a quick way to see who is hammering the web server. Write
/usr/local/bin/top-talkers, a Bash script, to this specification. A sample log is in
/srv/logs/access.log.
top-talkers [-n N] FILE
FILE is an access log in common log format: the first field of each line is the client
address.<count> <address>
— a single space between them.10.0.0.10 before 10.0.0.9).#.-n takes a positive whole number. Anything else: print top-talkers: invalid count to
stderr and exit with status 2.FILE is missing or unreadable: print top-talkers: cannot read FILE (with the actual name)
to stderr and exit with status 1.Your script is graded by running it against logs you have not seen, including every edge case above.
The machine is checked, rebooted, and checked again. A check passes only if it passes both times.
| Check | Objective |
|---|---|
| 01_top_five_by_default | Process text with pipelines: filter, count, sort |
| 02_count_option_and_ties | Process text with pipelines: filter, count, sort |
| 03_skips_comments_and_blanks | Process text with pipelines: filter, count, sort |
| 04_rejects_bad_counts | Handle options and arguments in a Bash script |
| 05_missing_file_and_empty_input | Report errors correctly: messages on stderr, meaningful exit status |
| 06_pure_bash | Handle options and arguments in a Bash script |
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 sortman 1 uniqman 7 localeman 1 grepman 1 bashman 1 test3 questions on the same topic, in the lab's Theory tab. They never affect the lab's grade. Here they are, to answer in place:
Why does `uniq -c` need its input sorted?
It only merges adjacent identical lines
uniq compares each line with the previous one only. Unsorted input gives several counts for the same value.
man 1 uniq
What does this print?
printf '10.0.0.9\n10.0.0.10\n' | LC_ALL=C sort | head -1
10.0.0.10
A plain text sort compares byte by byte: at the first difference "1" sorts before "9". For numeric order use sort -n, or sort -V for versions and addresses.
man 1 sort · executed in a sandbox
Which sort orders "count address" lines by count descending, then address ascending?
sort -k1,1nr -k2,2
Each -k limits a key to one field and carries its own flags: numeric and reversed for the count, plain for the address. -nr alone leaves ties in an unspecified order.
man 1 sort