Apache access log for the most common IP address bash script Apache access log for the most common IP address bash script bash bash

Apache access log for the most common IP address bash script


You can use this:

awk '{a[$1]++} END {for (i in a) print a[i],i | "sort -rnk1"}' access_log.txt5 10.23.234.04 250.40.56.782 8.45.98.2501 10.23.234.0

or

awk '{a[$1]++} END {for (i in a) print a[i],i}' access_log.txt | sort -rnk1

r in sort is reverse


To get html data

awk '{split($0,a,"http|[)]");print $1" - http"a[2]}' file66.249.73.234 - http://www.google.com/bot.html

Top print DNS only for top two records.

awk '{split($0,b,"http|[)]");a[$1" - http"b[2]]++} END {for (i in a) print a[i],i}' file | sort -rnk 1 | awk 'NR>2 {$0=$1FS$2} 1'