Tomcat访问日志中 ip请求次数统计shell脚本代码

中间件 12/28 阅读 339 views次 人气 0
摘要:

Tomcat访问日志中 ip请求次数统计shell脚本代码,Tomcat访问日志中 ip请求次数统计shell脚本代码,Tomcat访问日志中 ip请求次数统计shell脚本代码

日志样例:

10.209.252.35 - - [28/Dec/2018:19:24:22 +0800] "GET /amsportal HTTP/1.1" 302 -
10.209.252.35 - - [28/Dec/2018:19:24:22 +0800] "GET /amsportal HTTP/1.1" 302 -
10.209.252.35 - - [28/Dec/2018:19:24:22 +0800] "GET /amsportal HTTP/1.1" 302 -
10.209.252.35 - - [28/Dec/2018:19:24:23 +0800] "GET /amsportal/ HTTP/1.1" 302 -
10.209.252.35 - - [28/Dec/2018:19:24:23 +0800] "GET /amsportal/ HTTP/1.1" 302 -
10.210.81.37 - - [28/Dec/2018:19:28:27 +0800] "GET /amsportal/script/common/Validator.js HTTP/1.1" 200 23804
10.210.81.37 - - [28/Dec/2018:19:28:27 +0800] "GET /amsportal/style/blue/aqcommon/css/dropdown.css HTTP/1.1" 200 1864
10.210.81.37 - - [28/Dec/2018:19:28:27 +0800] "GET /amsportal/style/blue/aqcommon/css/app.src.css HTTP/1.1" 200 63066
10.210.81.37 - - [28/Dec/2018:19:28:27 +0800] "GET /amsportal/style/blue/ui_component/DHTMLXwindow/skins/dhtmlxwindows_dhx_blue.css HTTP/1.1" 200 24220
10.210.81.37 - - [28/Dec/2018:19:28:27 +0800] "GET /amsportal/style/blue/aqcommon/css/rightnotice.css HTTP/1.1" 200 3036
10.210.81.37 - - [28/Dec/2018:19:28:27 +0800] "GET /amsportal/style/blue/ui_component/ymPrompt/skin/qq/ymPrompt.css HTTP/1.1" 200 2620
10.210.81.37 - - [28/Dec/2018:19:28:27 +0800] "GET /amsportal/script/resources/resourceBundle_zh_CN.js HTTP/1.1" 200 28325
......


执行脚本:

cat localhost_access_log.2018-12-28.txt |awk '{print $1}'|sort -nr |uniq -c |sort -nr |more


统计结果:

# cat localhost_access_log.2018-12-28.txt |awk '{print $1}'|sort -nr |uniq -c |sort -nr |more
    179 10.210.81.37
    159 10.209.252.35


shell脚本:

#!/bin/sh
echo "input log file path"
read path
pa="$path"
cat $pa |awk '{print $1}'|sort -nr |uniq -c |sort -nr |more


执行结果:

# ./accessCount.sh 
input log file path
localhost_access_log.2018-12-28.txt
    181 10.210.81.37
    160 10.209.252.35


评论

表情

分享到: