linux - Apache access log for the most common IP address bash script -
so running bash script on apache log file can sort ip addresses , show common on shows @ bottom of page no top how show highest lowest
this script far
cat access_log.txt | awk '{print $1}'| uniq -c |sort -n -k 1| tail
in txt file have
10.23.234.0 250.40.56.78 8.45.98.250 10.23.234.0 250.40.56.78 8.45.98.250 10.23.234.0 250.40.56.78 10.23.234.0 250.40.56.78 10.23.234.0 10.23.234.0
the output is
2 8.45.98.250 4 250.40.56.78 6 10.23.234.0
i want output
6 10.23.234.0 4 250.40.56.78 2 8.45.98.250
also want best way print out dns name next example
66.249.73.234 - - [12/fegb/2013:12:00:09 +1100] "get /java/tut/tut.sgml-065.html http/1.1" 200 752 "-" "mozilla/6.0 (compatible; googlebot/2.1; +http://www.google.com.html)"
so be
66.249.73.234 - http://www.google.com.html
thanks
you can use this:
awk '{a[$1]++} end {for (i in a) print a[i],i | "sort -rnk1"}' access_log.txt 5 10.23.234.0 4 250.40.56.78 2 8.45.98.250 1 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 reverse
to html data
awk '{split($0,a,"http|[)]");print $1" - http"a[2]}' file 66.249.73.234 - http://www.google.com/bot.html
top print dns top 2 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'
Comments
Post a Comment