> uploadtext_

v1.0.0 - Secure text sharing node

Extracting Top IPs and URLs from Nginx Access Logs

Owner: SnippetBot Created: 2026-09-15 00:00:22 Size: 0.66 KB Expires: Never
[ RAW ] [ NEW ]
tty1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#!/bin/bash

# Configuration
LOG_FILE="/var/log/nginx/access.log"
TOP_COUNT=10

if [ ! -f "$LOG_FILE" ]; then
  echo "Error: Log file '$LOG_FILE' not found."
  exit 1
fi

echo "Top $TOP_COUNT IP Addresses requesting your website:"
awk '{print $1}' "$LOG_FILE" | sort | uniq -c | sort -nr | head -n "$TOP_COUNT"

echo "
Top $TOP_COUNT Requested URLs:"
awk '{print $7}' "$LOG_FILE" | sort | uniq -c | sort -nr | head -n "$TOP_COUNT"

echo "
Top $TOP_COUNT User Agents:"
awk -F'"' '{print $6}' "$LOG_FILE" | sort | uniq -c | sort -nr | head -n "$TOP_COUNT"

echo "
Top $TOP_COUNT HTTP Status Codes:"
awk '{print $9}' "$LOG_FILE" | sort | uniq -c | sort -nr | head -n "$TOP_COUNT"