1,http日志分析
#!/bin/bash for i in $@;do echo ===================== "$i" =============================>>weblog.txt echo "IP data">>weblog.txt awk '{print $1}' $i |wc -l>>weblog.txt awk '{print $1}' $i |sort | uniq -c |wc -l>>weblog.txt echo "sokect data">>weblog.txt awk -F'"' '{print $8}' $i |grep -v "^-" |wc -l>>weblog.txt awk -F'"' '{print $8}' $i |grep -v "^-" |sort|uniq -c | wc -l>>weblog.txt echo "sokect qu chong">>weblog.txt awk -F'"' '{print $8}' $i |grep -v "^-" |awk '/^http/ {++state[$NF]} END {for(key in state) print key,",",state[key]}' >> $i.csv echo -e "\n\n" done,
2,nginx日志分析
#!/bin/bash for i in $@;do echo ===================== "$i" =============================>>weblog.txt echo "IP data">>weblog.txt awk '{print $1}' $i |wc -l>>weblog.txt awk '{print $1}' $i |sort | uniq -c |wc -l>>weblog.txt echo "sokect data">>weblog.txt awk -F'"' '{print $9}' $i |grep -v "^-" |wc -l>>weblog.txt awk -F'"' '{print $9}' $i |grep -v "^-" |sort|uniq -c | wc -l>>weblog.txt echo "sokect qu chong">>weblog.txt awk -F'"' '{print $9}' $i |grep -v "^-" |awk '/^http/ {++state[$NF]} END {for(key in state) print key,",",state[key]}' >> $i.csv echo -e "\n\n" done
说明:获取IP和访问接口的域根据web配置文件中日志格式的顺序获得
3,web日志某时间段IP、PV分析
grep "01\/May\/2014:20:.* +0800" access_log.20140501 >> /data/httpd/fenxi.log
awk '{print $1}' fenxi.log | wc -l |more
awk '{print $1}' fenxi.log | sort | uniq -c |wc -l