截取Nginx日志文件中一周内的文件访问次数最多的记录
#!/bin/bash
#截取nginx日志文件中,一周内的文件访问次数最多的记录
#writen by zs
LANG=en_US.UTF-8
logfile=/www/logs/access.log
today=`date |awk '{printf("%s/%s"), $3, $2}' `
oneday=`date -d '-1 days'|awk '{printf("%s/%s"), $3, $2}' `
twoday=`date -d '-2 days'|awk '{printf("%s/%s"), $3, $2}' `
threeday=`date -d '-3 days'|awk '{printf("%s/%s"), $3, $2}' `
fourday=`date -d '-4 days'|awk '{printf("%s/%s"), $3, $2}' `
fiveday=`date -d '-5 days'|awk '{printf("%s/%s"), $3, $2}' `
sixday=`date -d '-6 days'|awk '{printf("%s/%s"), $3, $2}' `
grep -E "(${today}|${oneday}|${twoday}|${threeday}|${fourday}|${fiveday}|${sixday})" ${logfile} | awk '{print $7}' |awk -F'?' '{print $1}'|sort|uniq -c|sort -nr |head
-n 100 |tee -a /home/www/test.log