1、簡介localhost_access_log.xxxx-xx-xx.txt日誌文件
在xx/tomcat/logs目錄下存在localhost_access_log.xxxx-xx-xx.txt文件,以天爲單位進行日誌記錄。
而文件中的記錄的內容顯示如下:
關於文件中日誌記錄,可以在xx/tomcat/conf/server.xml中進行配置,默認配置如下:
其他配置項如下:
2、我們要做的,就是在此日誌的基礎上,進一步進行統計操作
具體實現腳本:
#!/bin/bash
date=`date -d "1 day ago" +%Y-%m-%d`
#date=`date +%Y-%m-%d`
log_dir=/root/software/tomcat7/logs/
f_log=/root/software/tomcat7/logs/localhost_access_log.$date.txt
if [ -f "$f_log" ]; then
if [ ! -f "$log_dir/access_log/$date.cot" ]; then
`touch $log_dir/access_log/$date.cot`
fi
cat $f_log |awk '{print $1}' |sort |uniq -c |sort -n > $log_dir/access_log/$date.cot
else
if [ ! -f "$log_dir/access_log/$date.cot" ]; then
touch $log_dir/access_log/$date.cot
fi
echo "$f_log doesn't exit" > $log_dir/access_log/$date.cot
fi
這段腳本的功能是:統計昨天的訪問記錄,並按訪問量將訪問用戶進行排序,放在指定的文件
執行效果,參考如下:
定時每天00:01執行: