Reading logs and spotting oddities

A log is a record of what happened, and most trouble leaves a trace in it before you notice anything else. The skill is asking it a narrow question and letting a pipeline answer with a count.

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 the counting pipeline run sort before uniq -c?
2 In grep 'result=fail' auth.log | cut -d" " -f3, what does -f3 keep?
3 What does sort -nr do to the output of uniq -c?
4 In a log, why is a success that comes right after a run of failures worth a closer look?

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.

Count the failed logins per source

This writes a short auth log into your home directory, keeps only the failed lines, reduces each one to its source field, and ranks the sources by how many failures each produced.

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.

{ for i in 1 2 3 4 5 6; do echo "user=mira src=203.0.113.14 result=fail"; done; for i in 1 2; do echo "user=root src=198.51.100.7 result=fail"; done; echo "user=dev src=192.0.2.55 result=fail"; echo "user=mira src=203.0.113.14 result=ok"; } > ~/auth.log; grep "result=fail" ~/auth.log | cut -d" " -f2 | 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