Linux Labs

First steps / Stage 12 of 15 · step 6 of 7

Count the errors in the logs

easy ~20 min
Not running Starting usually ~20 s
Report a problem

Situation

Last night an online shop kept answering its customers with errors. Its logs live in /var/log/shop, one file per part of the site. In the morning a colleague asks for a summary: which error codes there were and how many times each. "If you can't read one of the logs, that's fine — just keep the message about it separately, and I'll sort out the access."

The colleague keeps the summaries of earlier nights in ~/report/history.txt, one line per night.

Task

Make it so that:

  1. ~/report/errors-by-code.txt has, for each code found in ERROR lines, the number of such lines and the code itself — one line per code, separated by a space, the most frequent first;
  2. ~/report/failed.txt holds the error messages of the command that read the logs, and nothing else;
  3. a line for this night appears at the end of ~/report/history.txt, in the same form as the earlier ones: 2026-10-19 and the total number of ERROR lines. The earlier lines must stay where they are.

Read the logs as yourself, without sudo: the summary covers what is open to you.

Visible only to you. Saved as you type.

All notes

Lab goals

0 of 3
  • ~/report/errors-by-code.txt lists the count and code of each error, most frequent first — not checked yet
  • ~/report/failed.txt holds only the command's error messages — not checked yet
  • ~/report/history.txt keeps the earlier lines and ends with a line for 2026-10-19 — not checked yet

Hints

0 of 3 open · they open one at a time
Hint 1
Show the solution after 3 failed checks

Leave the lab?

The machine keeps running for 10 more minutes, then it is removed. Files are lost; completed goals stay.

Loading…