Recap - Log Summary
Part of the Bash Scripting section of Coddy's Terminal journey. Lesson 26 of 39.
Challenge
HardWrite summary.sh, a script that summarizes every web log under a folder. Each log line looks like this, with the path in field 7 and the status code in field 9:
10.0.0.5 - - [12/Mar/2026:10:01:22 +0000] "GET /index.html HTTP/1.1" 200 512- The folder is the only argument. With any other number of arguments, print
Usage: summary.sh FOLDERto stderr and exit with code 1. - If the argument is not a folder, print
Not a folder: NAMEto stderr, with the argument in place of NAME, and exit with code 2. - Read every file whose name ends in
.loganywhere under the folder, nested folders included. Other files are not logs. - Print
Requests: N, the number of log lines. - For each status code, print the code, a space and how many lines have it, one code per line, smallest code first.
- Print
Top path: PATH (N), the path requested most often and how many times.
Try it: run bash summary.sh logs. It prints:
Requests: 8
200 5
404 2
500 1
Top path: /index.html (3)Then run bash summary.sh logs/notes.txt: it prints Not a folder: logs/notes.txt and exits with code 2.
Try it yourself
All lessons in Bash Scripting
1Arguments And Exit Codes
Script ArgumentsAll The ArgumentsExit CodesChecking ArgumentsRecap - Unit Converter5Text Power Tools
Finding FilesBatch Work With xargsEditing Text With sedColumns With awkRecap - Log SummaryPractice on your own: Terminal playground