HANDS-ON TASK · 1 OF 1

Log report generator

Project: Log report generator

You're an SRE at esc bash. Every morning someone opens the web server's access log and reads it by hand to see who is hitting the service and what is breaking. That does not scale. Write a small, reusable script that turns the log into a short summary report.

Set up the project

Run this first. It prepares the machine for the task:

bash
curl -fsSL https://raw.githubusercontent.com/Esc-Bash/project-init-scripts/main/shell-scripting/project-1/init.sh | bash

This creates /root/mission/access.log. Every line has four space-separated fields: client IP, HTTP method, request path, and response status code. For example:

10.0.0.5 GET /api/users 200

What to build

Write /root/scripts/logreport.sh that takes two arguments: the path of the log to read, and the path of the report to write.

logreport.sh <input-log> <output-report>

Start the script with set -euo pipefail. Then:

  1. If it is not called with exactly two arguments, print a short usage message to stderr and exit with code 2.
  2. If the input log file does not exist, print an error to stderr and exit with code 1.
  3. Otherwise, read the log and write a report to the output path that contains these lines, using exactly these labels:
    • total requests: followed by the number of log lines.
    • top IP: followed by the busiest client IP and its count, like top IP: 10.0.0.5 (8).
    • error responses: followed by how many requests had a status code of 400 or higher.
    • one line per request path, <path>: <count>, for every path in the log.

Run your script against the sample log, writing the report to /root/answers/report.txt:

logreport.sh /root/mission/access.log /root/answers/report.txt

When the checks pass, press Submit.

Start the lab on the right to run checks.

Pass the checks to continue
Spin up a fresh environment and practice live.
linux-devops-basic · fresh machine · ready in under a minute