Short task: build a daily summary with a one-liner
From a gateway’s log you build the day’s summary, each part with a one-line command: the number of errors, the three addresses that sent the most requests, the users whose logins failed, a one-line summary built with command substitution, a check script whose output and errors go to separate files, and an alias that repeats the job tomorrow with one word.
Level 101 · 30 min
At every 08:30 morning meeting Daniel asks the same questions: "How many errors did the gateway have yesterday? Who sent the most requests? Whose logins failed?" Today you prepare the answers, and in a way that lets you repeat the job tomorrow in seconds.
A one-liner finishes a job in one line by chaining small tools with pipes (|): one filters, one cuts, one sorts, one counts. You saw them all in this section: redirection (>, >>, 2>), pipes, grep, cut, sort, uniq -c, wc -l, head, chaining (&&, ||), command substitution ($( )) and aliases (alias).
This is a short task: no commands are given, only goals. The log is the file /var/log/northwind/gateway.log; each line consists of fields separated by spaces: date time client-IP level message…. Example: 2026-03-14 08:02:11 10.20.4.37 ERROR login failed user=can.d. The level is INFO, WARN or ERROR. The content differs in every lab.
All results go into the directory ~/report. Build each pipe piece by piece: run the first command, look at the output, then add the next link.
What you will do in this lesson
- How many errors?
- The three busiest addresses
- Users whose logins failed
- The one-line summary
- The check script: output, errors and result apart
- For tomorrow: a one-word alias
- Short quiz
Skills you will earn
- Filtering and counting lines (grep, grep -c)
- Chaining commands conditionally (&&, ||, ;)
- Redirecting output to a file with > and >>
- Cutting fields (cut -d -f)
- Sorting and counting (sort, uniq -c)
- Finding the top requesters in a log
- grep options (-v -o -E -i -w)
- Command substitution ($( ), backticks)
- Counting lines (wc -l)
- Redirecting error output (2>)
- Reading the exit status ($?)
- Defining and removing aliases
- Editing and loading .bashrc (source)
← Editing files: first steps with nano and vim · Linux fundamentals · Capstone: investigate an incident folder and find the suspicious IP →
Start for free