Reading logs for a story

A log is a list of events, and a list of events becomes a story once you put it in order. This set covers picking fields out of a line, counting who was busy, why the sort before uniq matters, and how to read a run of failures without jumping to a conclusion.

4 questions 1 task Read the lesson

Questions

Each one is marked as you go, and the explanation arrives straight after, which is the part worth reading.

4 questions, marked as you go.

1 Why does awk '{print $1, $2, $4}' print the time, the user and the result?
2 Why must sort come before uniq -c?
3 Why is ISO 8601 a good timestamp format for a log you write yourself?
4 A run of failures ends in a success from the same source. What should you do?

Tasks

These need your own device. Run the command in Termux, then paste what it printed. The marking looks at what the output means, so spacing, version numbers and ordering do not matter. If you have not installed anything yet, the lesson covers the setup.

Turn a log into a timeline

This writes a short auth log and then reads it two ways: as a timeline of time, user and result, and as a ranking of the sources that failed. Read the shape of both, not the exact addresses.

Run this in Termux On your own device. Nothing on this page executes it. The command runs in your terminal, and this box only reads what you paste back.

printf '2026-10-25T09:01:00Z user=mira src=203.0.113.14 result=ok\n2026-10-25T09:02:10Z user=root src=198.51.100.7 result=fail\n2026-10-25T09:02:12Z user=root src=198.51.100.7 result=fail\n2026-10-25T09:03:00Z user=root src=198.51.100.7 result=ok\n' > ~/auth.log; awk '{print $1, $2, $4}' ~/auth.log; echo "== failures per source =="; grep 'result=fail' ~/auth.log | cut -d' ' -f3 | sort | uniq -c | sort -nr
Marking your own work Both halves of this are checked in your browser, with no server involved, so nothing stops you from pasting output you did not run. The tasks are written so that the easiest way to pass one is to actually do it and read the result, which is the whole intention.

All sets Read the lesson