|
按时间段获取日志
1
2
3
4
5
6
7
8
| 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 $0}' access_www.log > /tmp/acc.www.log
awk '/22\/Dec\/2015:00/,/22\/Dec\/2015:09/ {print $0}' access_www.log |head -3
awk '/22\/Dec\/2015:00/,/22\/Dec\/2015:09/ {print $0}' access_www.log |tail -3
============================================================================
|
#######################################################
统计链接数:
1
2
3
4
5
6
7
8
9
10
11
| netstat -tan | awk '/^tcp/{++state[$NF]}END{for (s in state) {print s"============"state}}'
netstat -tan|awk '/^tcp/{S[$6]++ } END {for(n in S) {print n "============" S[n]}}'
------------------------
[iyunv@iZ23eoou07sZ ~]# netstat -a|awk '/tcp/{S[$6]++ } END {for(n in S) {print n "============" S[n]}}'
TIME_WAIT============292
ESTABLISHED============13
SYN_RECV============2
LAST_ACK============3
LISTEN============5
[iyunv@iZ23eoou07sZ ~]#
# netstat -tn | awk '/^tcp/{lens=split($5,client,":");ip[client[1]]++}END{for (i in ip) print i,ip}'
|
#######################################################
统计每个IP的连接数:
1
2
3
4
| netstat -ntu | awk -F'[ :]+' '/^tcp/{print $6}'|sort |uniq -c |sort -rn|head -5
netstat -ntu | awk '{ print $5}' | 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 $5}' | cut -d : -f 1 | sort | uniq -c | sort -n -r |head -n 3
netstat -ntu | tail -n +3 | awk '{ print $5}' | 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数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| awk '{ip[$1]++}END{for (i in ip) {print ip, i}}' access_www.log |sort -rn -k1 |head -10
[salt@iZ23fxh0i4lZ nginx]$ awk '{ip[$1]++}END{for (i in ip) {print ip, i}}' access_www.log |sort -rn -k1 |head -10
6792 140.206.49.178
6106 66.249.69.247
4734 115.159.29.191
2501 42.121.119.229
2444 114.119.8.92
2179 10.162.85.26
1741 10.51.0.209
1710 121.37.61.220
1580 121.41.37.72
1568 66.249.75.95
[salt@iZ23fxh0i4lZ nginx]$
|
|
|