Linux Labs

First steps / Stage 12 of 15

Pipelines: an answer from several commands

Not running Starting usually ~20 s
Leave the lesson

Step 6 of 7 · lab · 20 mineasy

Count the errors in the logs

A summary of the night's error codes from the shop logs: a pipeline into a file, the command's errors into another one, the history appended.

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.

Lab · on your own

No commands are given in this lab: type them in the terminal yourself. Goals are checked on the machine after every command.

Goals

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

The machine is starting

Hints

0 of 3

Lab goals

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

Lab goals

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