Linux Labs

Bash: text processing and scripts / Stage 2 of 9 · step 7 of 9

A report from the nginx log

medium ~30 min
Not running Starting usually ~20 s
Report a problem

Situation

Your manager wants a report on the shop.lab.test store site for yesterday, 19 October: which requests the site took longest to handle, and how many bytes it sent with each response code. The site runs on nginx; its request log is /var/log/nginx/shop.access.log, and the line format is set in /etc/nginx/conf.d/shop-log.conf.

The manager compares reports from different days, so the report always has the same layout.

Task

Build ~/report.txt out of two sections:

[slowest]
<time> <URL>
…
[bytes]
<code> <bytes>
…
  1. The [slowest] section holds the five longest requests of 19 October: the request time as written in the log and the request URL, separated by a space. The longest one first.
  2. The [bytes] section holds every response code that occurs on 19 October and the sum of bytes sent with that code during the day ($body_bytes_sent), separated by a space. Codes in ascending order.

The day runs from 00:00:00 to 23:59:59 by the log's clock. Only read the logs, don't change them. First look at what you are working with: ls -l /var/log/nginx and head -n 3 of the log. Build each section as a pipeline one link at a time and watch the output on screen; send it to the file once the output is right.

Visible only to you. Saved as you type.

All notes

Lab goals

0 of 2
  • The [slowest] section lists the five longest requests of 19 October — time and URL, the longest first — not checked yet
  • The [bytes] section holds the sum of bytes of 19 October for each response code, codes in ascending order — 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…