#!/bin/bash
# HJ test trigger file
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
directory=/home/houjiao/test/
filelist=`ls $directory`
#for file in $filelist
for file in *.dat
do
exist=$(lsof ${directory}${file})
if [ $? ] && [ `echo $file |grep 'log'` ]; then
# 是否匹配到Match str列 将没匹配到的行打印出来
echo "start analsys $file NO Match str is :"
cat -n $file | grep -v 'Match str:'
# 统计访问网站和搜索触发的行数
cat -n $file | grep '\.c[on]m*' > count.site
netrow=`cat count.site |wc -l`
allrow=`cat $file |wc -l`
seachrow=$(($allrow - $netrow))
echo "According to the website's count $netrow"
echo "According to the search's count $seachrow"
# 对比相同文件名的trigger和trigger_log行数是否相等
name1=${file%log*.dat} #从尾部开始将log删除
name2=`echo $file |cut -d '_' -f 4`
filename=${name1}${name2} #去掉log后的文件名
if [ -e ${directory}${filename} ]; then
trigger=`cat $filename |wc -l`
test $trigger -eq $allrow && echo "$filename equal with $file" || echo "$filename not equal with $file"
fi
#若同一个用户出现两次以上检测 规则是否在rule文件中
user=`cat $file | cut -d ',' -f 1 |uniq -c |awk '$1 > 2 {print $2}'` #得出两次或两次以上触发的用户有哪些
for userid in $user
do
#将match rule:id 和match str:www.taobao.com这两列存入rule.test
cat $file |grep "^$userid"|cut -d ':' -f 2,3 >> rule
done
# 在rule.test里根据match str后面的内容 在规则文件里查找是否有匹配的
while read line
do
fname=${line%%,*} #获取最终rule文件名
ctent=${line##* }
content=${ctent%%,*} #获取最终要匹配的内容
if [ ! `cat -n ${fname}.rule|grep "$content"` ];then
echo "$content is not in ${fname}.rule"
fi
done < rule
fi
done
很山寨的程序,这可是我的第一个shell啊。。明天经理要看,,希望他看后的狂虐可以让我提高一大截。