Get logs by time period
Sed-n '/22\/dec\/2015:00/,/22\/dec\/2015:50/p ' localhost_access_log.2015-11-10.txt >/tmp/acc.www.log sed-n '/22\ /dec\/2015:00/,/22\/dec\/2015:50/p ' localhost_access_log.2015-11-10.txt |head-3 sed-n '/22\/Dec\/2015:00/,/22\/Dec \/2015:50/p ' localhost_access_log.2015-11-10.txt |tail-3 ======================================awk '/22\/Dec\/ 2015:00/,/22\/dec\/2015:09/{print $} ' access_www.log >/tmp/acc.www.log awk '/22\/dec\/2015:00/,/22\/dec\/ 2015:09/{print $} ' access_www.log |head-3 awk '/22\/dec\/2015:00/,/22\/dec\/2015:09/{print $} ' access_www.log |tail- 3============================================================================
#######################################################
Statistics Link Number:
Netstat-tan | awk '/^tcp/{++state[$NF]}end{for (s in state) {print S "============" State[s]}} ' Netstat-tan|awk '/^tcp/{s[$6]++} END {fo R (n in S) {print n "============" S[n]}} '------------------------[[email protected] ~]# Netstat-a|awk '/tcp/{s[$6]++} EN D {for (n in S) {print n "============" S[n]}} ' time_wait============292established============13syn_recv============ 2last_ack============3listen============5[[email protected] ~]# # Netstat-tn | awk '/^tcp/{lens=split ($5,client, ":"); ip[client[1]]++}end{for (i in IP) print I,ip[i]} '
#######################################################
Count the number of connections per IP:
Netstat-ntu | Awk-f ' [:]+ '/^tcp/{print $6} ' |sort |uniq-c |sort-rn|head-5netstat-ntu | awk ' {print $} ' | Cut-d:-F 1 | Sort | uniq-c| Sort-n-R | Head-n 5 | Grep-v 127.0.0.1 "Netstat-ntu | Tail-n +3 | awk ' {print $} ' | Cut-d:-F 1 | Sort | uniq-c | Sort-n-R |head-n 3netstat-ntu | Tail-n +3 | awk ' {print $} ' | Egrep-o "[0-9]{1,3}. [0-9] {1,3}. [0-9] {1,3}. [0-9] {1,3} "| Sort | uniq-c | Sort-n-R
#######################################################
IP number of the statistics log
awk ' {ip[$1]++}end{for (i in IP) {print ip[i], i}} ' Access_www.log |sort-rn-k1 |head-10 [[email protected] nginx]$ awk ' {ip[$1]++}end{for (i in IP) {print ip[i], i}} ' Access_www.log |sort-rn-k1 |head-106792 140.206.49.1786106 66.249.69. 2474734 115.159.29.1912501 42.121.119.2292444 114.119.8.922179 10.162.85.261741 10.51.0.2091710 121.37.61.2201580 121.41.37.721568 66.249.75.95[[email protected] nginx]$
This article is from the "Struggle Bar" blog, please be sure to keep this source http://lvnian.blog.51cto.com/7155281/1727079
Shell intercept Log Statistics link count log IP