码迷,mamicode.com
首页 > 其他好文 > 详细

提取最近一小时的访问次数

时间:2014-10-09 19:08:58      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:sed提取 自动获取

times=`tail -1  /Data/logs/nginx/access.log | awk ‘{print $4}‘`

m_time=`echo ${times} | awk -F: ‘{print $2}‘`

for i in 01 02 03 04 05 06 07 08 09;do

    if [ $i -eq ${m_time} ];then

        m_time=`echo ${m_time#0}`

    fi

done

if [ ${m_time} = "00" ];then

    s_time="23"

else

    let "s_time=${m_time}-1"

    num=`expr length ${s_time}`

    if [ ${num} -eq 1 ];then

        s_time="0${s_time}"

    fi

fi

for i in  0 1 2 3 4 5 6 7 8 9;do

    if [ $i -eq ${m_time} ];then

        m_time="0${m_time}"

    fi

done

time=`echo ${times#[} | sed "s/:${m_time}:/:${s_time}:/"`

time=`echo ${time} | awk -F/ ‘{print $1"\\\/"$2"\\\/"$3}‘`

times=`echo ${times} | awk -F/ ‘{print $1"\\\/"$2"\\\/"$3}‘`


echo "Start time is ${time}"

echo "Stop time is ${times#[}"

st_time=`date "+%H:%M:%S"`

echo "Start time is ${st_time}"

sed -n "/${time}/,/${times#[}/p" /Data/logs/nginx/access.log | awk ‘{print $1}‘ | sort | uniq -c | sort -nr | head -15

st_time=`date "+%H:%M:%S"`

echo "Stop time is ${st_time}"


提取最近一小时的访问次数

标签:sed提取 自动获取

原文地址:http://syydrwyl.blog.51cto.com/5620979/1561748

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!