免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4150 | 回复: 10
打印 上一主题 下一主题

Shell 脚本实现日志比较 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-08-01 19:58 |只看该作者 |倒序浏览
各位大侠帮个忙!谢啦!
我的日志sms.log信息如下:
[monitor@cat ~]$ sudo grep 'mobile cat' /usr/local/cat_proxy/mobile/log/sms.log

2011-08-01 17:19:03,860 [INFO] RecvMessage ==>[msgId=***, srcTermId=10658630, destTermId=***, content=This is mobile cat.]
2011-08-01 17:19:03,860 [INFO] SendMessage ==>[msgId=***, srcTermId=10658630, destTermId=***, content=This is mobile cat.]
2011-08-01 18:27:49,116 [INFO] RecvMessage ==>[msgId=***, srcTermId=10658630, destTermId=***, content=This is mobile cat.]
2011-08-01 18:27:49,116 [INFO] SendMessage ==>[msgId=***, srcTermId=10658630, destTermId=***, content=This is mobile cat.]
2011-08-01 18:43:26,679 [INFO] RecvMessage ==>[msgId=***, srcTermId=10658630, destTermId=***, content=This is mobile cat.]
2011-08-01 18:43:26,680 [INFO] SendMessage ==>[msgId=***, srcTermId=10658630, destTermId=***, content=This is mobile cat.]
2011-08-01 18:57:53,881 [INFO] RecvMessage ==>[msgId=***, srcTermId=10658630, destTermId=***, content=This is mobile cat.]
2011-08-01 18:57:53,881 [INFO] SendMessage ==>[msgId=***, srcTermId=10658630, destTermId=***, content=This is mobile cat.]
2011-08-01 19:13:01,199 [INFO] RecvMessage ==>[msgId=***, srcTermId=10658630, destTermId=***, content=This is mobile cat.]
2011-08-01 19:13:01,199 [INFO] SendMessage ==>[msgId=***, srcTermId=10658630, destTermId=***, content=This is mobile cat.]
2011-08-01 19:28:02,078 [INFO] RecvMessage ==>[msgId=***, srcTermId=10658630, destTermId=***, content=This is mobile cat.]
2011-08-01 19:28:02,078 [INFO] SendMessage ==>[msgId=***, srcTermId=10658630, destTermId=***, content=This is mobile cat.]
2011-08-01 19:43:05,869 [INFO] RecvMessage ==>[msgId=***, srcTermId=10658630, destTermId=***, content=This is mobile cat.]
2011-08-01 19:43:05,869 [INFO] SendMessage ==>[msgId=***, srcTermId=10658630, destTermId=***, content=This is mobile cat.]

怎样用Shell脚本实现每15分钟查看一下sms.log日志信息,如果输出的包含'mobile cat'的行数大于上个15分钟检测输出的值,并输出0,否则输出1?

谢谢啦!

论坛徽章:
0
2 [报告]
发表于 2011-08-01 20:08 |只看该作者
还有啊!
sms日志每天凌晨00:00清空啊!

谢谢啦!

论坛徽章:
0
3 [报告]
发表于 2011-08-01 20:34 |只看该作者
grep 'mobile cat' sms.log>test1
k=`awk -F, '{a[$3]++}END{print a[$3]}' test1`
if [ "$k" > 15 ]
then
echo "0"
else
echo "1"
fi
rm -rf test1

论坛徽章:
0
4 [报告]
发表于 2011-08-01 20:41 |只看该作者
回复 3# lz66


    非常感谢你能回复!
    不好意思能稍作解释一下么?
    比如a[$3] ?
    试了一下 awk -F, '{a[$3]++}END{print a[$3]}' /usr/local/cat_proxy/mobile/log/sms.log  输出的结果为2啊??
    谢谢啦!

论坛徽章:
0
5 [报告]
发表于 2011-08-01 20:44 |只看该作者
我在看看,我试了是14的

论坛徽章:
0
6 [报告]
发表于 2011-08-01 20:50 |只看该作者
我在看看,我试了是14的
lz66 发表于 2011-08-01 20:44



    谢谢!
    不好是我搞错了!
    怎么和15比较呢?我的意思是每十五分钟和上一次检测输出的行数比较啊?
    还有就是每天凌晨00:00 sms日志要清零的啊?
    谢谢啦!大侠!

论坛徽章:
0
7 [报告]
发表于 2011-08-01 20:56 |只看该作者
grep 'mobile cat' sms.log>test1
k=`awk -F, '{a[$3]++}END{print a[$3]}' test1`
if [ "$k" -gt 15 ]
then
echo "0"
else
echo "1"
fi
rm -rf test1

论坛徽章:
0
8 [报告]
发表于 2011-08-01 20:57 |只看该作者
我也记错了,你可以每十五分钟执行一次脚本就行了

论坛徽章:
3
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:51:162015年亚洲杯之阿曼
日期:2015-04-07 20:00:59
9 [报告]
发表于 2011-08-01 21:36 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
10 [报告]
发表于 2011-08-01 21:46 |只看该作者
while true
do
grep 'mobile cat' sms.log>test1
awk -F, '{a[$3]++}END{print a[$3]}' test1 >> sum
rm -rf test1
k=`tail -2 sum|sed -n '1 p'`
b=`tail -1 sum|sed -n '1 p'`
if [ "$k" -gt "$b" ];then
echo "0"
else
echo "1"
fi
sleep 15
done
不知道这样行不行,我没试
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP