shell 截取日志 统计链接数 统计日志ip
2015-12-22 10:29
507 查看
按时间段获取日志
#######################################################
统计链接数:
#######################################################
统计每个IP的连接数:
#######################################################
统计日志的IP数
本文出自 “奋斗吧” 博客,请务必保留此出处http://lvnian.blog.51cto.com/7155281/1727079
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 ============================================================================
#######################################################
统计链接数:
netstat -tan | awk '/^tcp/{++state[$NF]}END{for (s in state) {print s"============"state[s]}}' netstat -tan|awk '/^tcp/{S[$6]++ } END {for(n in S) {print n "============" S }}' ------------------------ [root@iZ23eoou07sZ ~]# netstat -a|awk '/tcp/{S[$6]++ } END {for(n in S) {print n "============" S }}' TIME_WAIT============292 ESTABLISHED============13 SYN_RECV============2 LAST_ACK============3 LISTEN============5 [root@iZ23eoou07sZ ~]# # netstat -tn | awk '/^tcp/{lens=split($5,client,":");ip[client[1]]++}END{for (i in ip) print i,ip[i]}'
#######################################################
统计每个IP的连接数:
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数
awk '{ip[$1]++}END{for (i in ip) {print ip[i], i}}' access_www.log |sort -rn -k1 |head -10 [salt@iZ23fxh0i4lZ nginx]$ awk '{ip[$1]++}END{for (i in ip) {print ip[i], 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]$
本文出自 “奋斗吧” 博客,请务必保留此出处http://lvnian.blog.51cto.com/7155281/1727079
相关文章推荐
- Win10 RS1预览版11082无法打开PowerShell没反应的解决办法
- xshell putty等终端,如何记录终端输入输出
- C程序调用shell脚本共有三种方法
- shell文本过滤编程(九):sed命令
- shell文本过滤编程(七):awk之变量传递
- shell文本过滤编程(八):awk之内置函数
- shell内置命令集合
- 今天领导分享了一个探测端口的命令-linux下提示bash:command not found
- AD回收站
- CRLF line terminators导致shell脚本报错:command not found
- 在XShell中使用sz和rz命令下载和上传文件
- CentOS 7.0之配置静态ip XShell连接
- SharePoint 2013 使用 PowerShell 更新用户
- Xshell启动时显示丢失MSVCP110.dll解决方法
- shell脚本学习(三)
- 右键git bash here和git gui here失效恢复
- DOS的命令、Linux的shell和window下的cmd杂谈
- HBase shell基本用法
- shell的内置命令
- shell函数【参数传递及输入输出】&内置函数