#!/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啊。。明天經理要看,,希望他看后的狂虐可以讓我提高一大截。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
