apache日誌統計 按小時,分鐘統計url訪問次數

wangzhensheng發表於2009-06-27

####################按小時統計url訪問次數
# $1 url

#!/bin/sh

if [ "$1" = "" ]
then
echo "Url is null ... EXIT"
exit 1
fi

LOG='/www/apache_log'
HOUR="`seq -w 0 23`"
files="`ls -trl ${LOG}/web-?*.log | awk '{print $9}'`"
url="$1"


export LOG HOUR files url
for file in $files
do
for a in ${HOUR}
do
num=`cat ${file} |awk '{print $4"t"$7}' |grep "${url}"|grep "/2009:${a}"|wc -l`
echo "${file}:${a} ${num}"
echo "---"
done
echo "====================================================================="
done

##########################################分鐘統計指定url訪問次數
# $1 url
# $2 yyyy:HH

#!/bin/sh

if [ "$1" = "" ] || [ "$2" = "" ]
then
echo "avg is null ... EXIT"
exit 1
fi

url="$1"
DATE="$2"

LOG='/www/apache_log'
M="`seq -w 0 59`"
files="`ls -trl ${LOG}/web-?*.log | awk '{print $9}'`"


export LOG HOUR files url
for file in $files
do
for a in ${M}
do
num=`cat ${file} |awk '{print $4"t"$7}' |grep "${url}"|grep "${DATE}:${a}"|wc -l`
echo "${file}:${DATE}:${a} ${num}"
echo "---"
done
echo "====================================================================="
done

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8806316/viewspace-1023552/,如需轉載,請註明出處,否則將追究法律責任。

相關文章