nginx统计

#!/bin/bash

logs_path="/usr/local/nginx/logs/"

mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/

mv ${logs_path}access.videos.cfdow.com.log ${logs_path}$(date -d "yesterday" +"%Y")/$(d

ate -d "yesterday" +"%m")/access.videos.cfdow.com.log.$(date -d "yesterday" +"%Y%m%d")

#cp ${logs_path}access.videos.cfdow.com.log ${logs_path}$(date -d "yesterday" +"%Y")/$(

date -d "yesterday" +"%m")/access.videos.cfdow.com.log.$(date -d "yesterday" +"%Y%m%d")

kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)

cat /dev/null > /usr/local/src/tongji

for ((i=1; i<8; ++i))  

do  

        d=$(date -d "${i} day ago" +"%m%d")

        file=cfdow12${d}02VA0.flv

        #echo $file

        size=$(ls -al /www/videos/ | grep "${file}" | awk '{print $5}')

        #echo $size

        #dakai=$(cat ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%

m")/access.videos.cfdow.com.log.$(date -d "yesterday" +"%Y%m%d") | grep "GET /${file} H

TTP/1.1" | wc -l)

        #wanzheng=$(cat ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" 

+"%m")/access.videos.cfdow.com.log.$(date -d "yesterday" +"%Y%m%d") | grep "GET /${file

} HTTP/1.1" | grep "${size}" | wc -l)

        dakai=$(cat ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m

")/access.videos.cfdow.com.log.$(date -d "yesterday" +"%Y%m%d") | grep "GET /${file} HT

TP/1.1" | wc -l)

        dk_91nbs=$(cat ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +

"%m")/access.videos.cfdow.com.log.$(date -d "yesterday" +"%Y%m%d") | grep "GET /${file}

 HTTP/1.1" | grep "http://videos.cfdow.com/bdjcsp/flvplayer.swf?vcastr_file=http://vide

os.cfdow.com/${file}" | wc -l)

        dk_9666=$(cat ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"

%m")/access.videos.cfdow.com.log.$(date -d "yesterday" +"%Y%m%d") | grep "GET /${file} 

HTTP/1.1" | grep "http://videos.cfdow.com/bd9666/flvplayer.swf?vcastr_file=http://video

s.cfdow.com/${file}" | wc -l)

        wanzheng=$(cat ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +

"%m")/access.videos.cfdow.com.log.$(date -d "yesterday" +"%Y%m%d") | grep "GET /${file}

 HTTP/1.1" | grep "${size}" | wc -l)

        wz_91nbs=$(cat ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +

"%m")/access.videos.cfdow.com.log.$(date -d "yesterday" +"%Y%m%d") | grep "GET /${file}

 HTTP/1.1" | grep "${size}" | grep "http://videos.cfdow.com/bdjcsp/flvplayer.swf?vcastr

_file=http://videos.cfdow.com/${file}" | wc -l)

        wz_9666=$(cat ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"

%m")/access.videos.cfdow.com.log.$(date -d "yesterday" +"%Y%m%d") | grep "GET /${file} 

HTTP/1.1" | grep "${size}" | grep "http://videos.cfdow.com/bd9666/flvplayer.swf?vcastr_

file=http://videos.cfdow.com/${file}" | wc -l)

        echo "====== 观看${file} ========" >>/usr/local/src/tongji

        echo "观看了:${dakai} 次">>/usr/local/src/tongji

        echo "完整观看了:${wanzheng} 次">>/usr/local/src/tongji

        echo "通过http://data2.91nbs.com/hd11/bdjcsp/index.html点击,观看了:${dk_91nbs

} 次">>/usr/local/src/tongji

        echo "通过http://91nbs.9666.cn/hd12/bd9666/index.html点击,观看了:${dk_9666} 

次">>/usr/local/src/tongji

        echo "通过http://data2.91nbs.com/hd11/bdjcsp/index.html点击,完整观看了:${wz_9

1nbs} 次">>/usr/local/src/tongji

        echo "通过http://91nbs.9666.cn/hd12/bd9666/index.html点击,完整观看了:${wz_966

6} 次">>/usr/local/src/tongji

        echo "=========================================">>/usr/local/src/tongji

        echo "">>/usr/local/src/tongji

done 

/usr/sbin/sendmail -t <<EOF

From: <root@localhost>

To:[email protected];[email protected]

#To:[email protected];[email protected]

Subject:视频观看分析229服务器

$(date -d "yesterday" +"%Y%m%d") 日志

$(cat /usr/local/src/tongji)

刘洋

EOF

cat /dev/null > /usr/local/src/tongji

相关推荐