标签: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