This shell script analyzes an Nginx access log file and provides insightful statistics about your web traffic.
Each line in the access log typically contains:
- IP Address
- Date and Time
- Request Method and Path
- Response Status Code
- Response Size
- Referrer
- User Agent
The script processes the log file and displays:
- Top 5 IP addresses with the most requests
- Top 5 most requested paths
- Top 5 response status codes
- Top 5 user agents
- Reads the log file line by line
- Extracts relevant fields using tools like
awk,uniq, orsort - Sorts and counts occurrences
- Displays the top 5 results for each category in a user-friendly format
Top 5 IP addresses with the most requests:
192.168.1.10 - 120 requests
203.0.113.5 - 98 requests
...
Top 5 most requested paths:
/v1-list-workspaces - 127 requests
/v1-list-timezone-teams - 75 requests
...
Top 5 response status codes:
200 - 300 times
404 - 25 times
...