#!/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:'
# 統(tǒng)計(jì)訪問網(wǎng)站和搜索觸發(fā)的行數(shù)
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"
# 對(duì)比相同文件名的trigger和trigger_log行數(shù)是否相等
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
#若同一個(gè)用戶出現(xiàn)兩次以上檢測(cè) 規(guī)則是否在rule文件中
user=`cat $file | cut -d ',' -f 1 |uniq -c |awk '$1 > 2 {print $2}'` #得出兩次或兩次以上觸發(fā)的用戶有哪些
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里根據(jù)match str后面的內(nèi)容 在規(guī)則文件里查找是否有匹配的
while read line
do
fname=${line%%,*} #獲取最終rule文件名
ctent=${line##* }
content=${ctent%%,*} #獲取最終要匹配的內(nèi)容
if [ ! `cat -n ${fname}.rule|grep "$content"` ];then
echo "$content is not in ${fname}.rule"
fi
done < rule
fi
done
很山寨的程序,這可是我的第一個(gè)shell啊。。明天經(jīng)理要看,,希望他看后的狂虐可以讓我提高一大截。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

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