nginx统计用户访问量脚本

#!/bin/bash

#本脚本用来统计特定时间段内,独立访问的用户数量

for s in `ls | grep -v error.log | grep -v test.sh | grep -v access1.log`

#for s in access_teach.log access_live.log

do

cat $s | awk '$4 >="[17/Jul/2017:08:30:00" && $4 <="[17/Jul/2017:18:00:00"'  | awk '{print $1}' >>/tmp/tmp.txt

name=`echo $s | cut -d\. -f 1`

echo "$name访问量为 :"

#获取某个时间段的数量

cat $s | awk '$4 >="[17/Jul/2017:08:30:00" && $4 <="[17/Jul/2017:18:00:00"'  | awk '{print $1}'|sort | uniq -c |wc -l

done

echo "总访问量为:"

cat /tmp/tmp.txt | sort | uniq -c |wc -l

echo ''> /tmp/tmp.txt

-------------------------------------------------------版本二--------------------------------------------------------------

设置变量


#!/bin/bash

#本脚本用来统计特定时间段内,独立访问的用户数量

#设立统计的开始和结束的时间

first="[17/Jul/2017:08:30:00"

last="[17/Jul/2017:23:00:00"

for s in `ls | grep -v error.log | grep -v test.sh | grep -v access1.log`

#for s in access_teach.log access_live.log

do

echo $first

cat $s | awk -v First="$first" -v Last="$last" '$4 >=First && $4 <=Last'  | awk '{print $1}' >>/tmp/tmp.txt

name=`echo $s | cut -d\. -f 1`

echo "$name访问量为 :"

cat $s | awk -v First="$first" -v Last="$last" '$4 >=First && $4 <=Last'  | awk '{print $1}'|sort | uniq -c |wc -l

done

echo "总访问量为:"

cat /tmp/tmp.txt | sort | uniq -c |wc -l

echo ''> /tmp/tmp.txt

你可能感兴趣的:(nginx统计用户访问量脚本)