>_ IzzyLab

Hands-on task

This task is step 19 of the course “Text in the terminal: grep, sed, awk”

Who is scraping the shop: top 3 IPs

medium~7 min

The shop is slow — looks like someone is scraping the catalog. /var/log/nginx/shop_access.log is an nginx access log, the IP is the first field. Find the three IPs that sent the most requests and write them to /root/top_ips.txt — one address per line, the most active first, without counts.

What you'll practise:
  • pipeline
  • awk
  • sort
  • uniq -c
  • head

Topic breakdown

Finding the most active clients is classic frequency analysis with a pipeline: extract a column, sort, count repeats, sort by the count and take the top. Each utility does one step and passes the stream on. Two common mistakes: forgetting the first sort (then uniq -c counts the same IPs in several pieces) and sorting the counts as text (then 9 ends up above 12).

What's checked

  1. /root/top_ips.txt has three lines
  2. top 3 IPs by descending request count

What it looks like