说明,本脚本分析squid日志,主要统计ip地址访问的域名,并对访问次数进行
计数。可以实现员工访问记录的监控。
#!/bin/sh
SLog="/qmail/log/temp.txt"
IPs=`awk '{ print $1 }' $SLog | sort | uniq`
#Doms=`awk -F"/" '{ print $5 }' $SLog|sort|uniq|grep -E "^[a-zA-Z0-9][a-z0-9]{0,}.\W.{1,}(com|cn|com.cn|net)$"`
Doms=`awk '{ print $2 }' $SLog | sort | uniq`
#echo $Doms
echo -e "+-----------------+-----------------------------+-------+"
echo -e "|      IP         |      Site and Domain        | Count |"
echo -e "+-----------------+-----------------------------+-------+"
for ip in $IPs
do
        #ip_total=`grep "$ip" $SLog | wc -l`
        #echo -e "$ip\t$ip_total"
        for dom in $Doms
        do
                count=`grep "$ip" $SLog | grep "$dom" | wc -l`
                if [ "$count" -gt 0 ]
                then
                        echo -e "|  $ip  |    $dom    |   $count   |"
                        echo -e "+-----------------+-----------------------------+-------+"
                fi
        done
done