#!/bin/bash
GREEN_COL='\033[32m'
NONE_COL='\033[0m'
line='echo ++++++++++++++++++++++++++++++++++'
read -p "请输入日志文件:" logfile
echo
PV=$(cat $logfile | wc -l)
UV=$(cut -f1 -d' ' $logfile | sort | uniq | wc -l)
Average_PV=$(echo "scale=2;$PV/$UV" | bc)
declare -A IP
while read ip other
do
let IP[$ip]+=1
done < $logfile
declare -A STATUS
while read ip dash user time zone method file protocol code size other
do
let STATUS[$code]++
done < $logfile
while read ip dash user time zone method file protocol code size other
do
let Body_size+=$size
done < $logfile
declare -A URI
while read ip dash user time zone method file protocol code size other
do
let URI[$file]++
done < $logfile
echo -e "\033[91m\t日志分析数据报表\033[0m"
$line
echo -e "累计PV量: $GREEN_COL$PV$NONE_COL"
echo -e "累计UV量: $GREEN_COL$UV$NONE_COL"
echo -e "平均用户访问量: $GREEN_COL$Average_PV$NONE_COL"
$line
echo -e "累计访问字节数: $GREEN_COL$Body_size$NONE_COL Byte"
$line
for i in 200 404 500
do
if [ ];then
echo -e "$i状态码次数:$GREEN_COL $NONE_COL"
else
echo -e "$i状态码次数:$GREEN_COL 0 $NONE_COL"
fi
done
$line
for i in
do
printf "%-15s的访问次数为: $GREEN_COL%s$NONE_COL\n" $i
done
echo
echo -e "$GREEN_COL访问量大于500的URI:$NONE_COL"
for i in ""
do
if [ ${URI["$i"]} -gt 500 ];then
echo "-----------------------------------"
echo "$i"
echo "次"
echo "-----------------------------------"
fi
done