刚接触shell 第一个处女小小程序
2013-06-07 17:43
309 查看
#!/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啊。。明天经理要看,,希望他看后的狂虐可以让我提高一大截。
# 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啊。。明天经理要看,,希望他看后的狂虐可以让我提高一大截。
相关文章推荐
- SHELL 编程入门与提高(一)第一个shell程序
- 《Linux程序设计》第四版第二章 我的第一个shell程序:CD唱片应用程序
- 第一个shell程序:hello world
- 用Java时写的第一个小小RPG游戏程序(第一版)
- 我的第一个shell程序
- 第一个shell程序
- 第一个shell程序
- 第一个小小程序
- OC---第一个OC程序(使用GNUstep的shell编译执行)
- 第一个shell程序----压缩android源码
- Linux Shell编程(2)——第一个shell程序
- Linux Shell编程(2)——第一个shell程序
- 全面接触TDD - 1. 第一个基于TDD的程序
- 为了忘却的纪念----开始从操就业的第一个SHELL程序
- nodeJs初接触(一)第一个程序代码hello world!
- Linux Shell 之 我的第一个Shell程序
- 第一个自编的MFC小小程序-ASC码正反查询器-分享初学MFC!
- 亲密接触Java手机程序设计(三):第一个Java手机程序--Hello World
- 我的第一个shell程序
- 亲密接触Java手机程序设计(三):第一个Java手机程序--Hello World