#!/bin/bash
#本腳本用來(lái)統(tǒng)計(jì)特定時(shí)間段內(nèi),獨(dú)立訪問(wèn)的用戶數(shù)量
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訪問(wèn)量為 :"
#獲取某個(gè)時(shí)間段的數(shù)量
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 "總訪問(wèn)量為:"
cat /tmp/tmp.txt | sort | uniq -c |wc -l
echo ''> /tmp/tmp.txt
-------------------------------------------------------版本二--------------------------------------------------------------
設(shè)置變量
#!/bin/bash
#本腳本用來(lái)統(tǒng)計(jì)特定時(shí)間段內(nèi)条篷,獨(dú)立訪問(wèn)的用戶數(shù)量
#設(shè)立統(tǒng)計(jì)的開始和結(jié)束的時(shí)間
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訪問(wèn)量為 :"
cat $s | awk -v First="$first" -v Last="$last" '$4 >=First && $4 <=Last'? | awk '{print $1}'|sort | uniq -c |wc -l
done
echo "總訪問(wèn)量為:"
cat /tmp/tmp.txt | sort | uniq -c |wc -l
echo ''> /tmp/tmp.txt