目的:统计某段时间nginx日志中的访问IP等相关信息
#!/bin/bash
for i in `seq -w 0 59`
do
sum=0
echo -n "Time:2019-04-22 15:$i "
echo -n "Ip:$(sed -n "/22\/Apr\/2019:15:$i:00/,/22\/Apr\/2019:15:$i:59/p" /opt/nginx/logs/logs_saved/www.yyjzt.com.access.log.2019-04-23-00 | awk '{print $1}' | sort -rn | uniq -c |wc -l ) "
for n in $(sed -n "/22\/Apr\/2019:15:$i:00/,/22\/Apr\/2019:15:$i:59/p" /opt/nginx/logs/logs_saved/www.yyjzt.com.access.log.2019-04-23-00 | awk '{print $1}' | sort -rn | uniq -c |sort -rn|awk '{print $1}')
do
let sum+=n
done
echo -e "Count: $sum\n"
done