免费注册 查看新帖 |

Chinaunix

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

关于日志审查 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-09-19 15:03 |只看该作者 |倒序浏览
我想做一个关于查询日志中在一段时间内是否存在某一个字符串的工作 具体的日志形势如下
Sep 19 09:39:19 localhost kernel: imklog 3.22.1, log source = /proc/kmsg started.
Sep 19 09:39:19 localhost rsyslogd: [origin software="rsyslogd" swVersion="3.22.1" x-pid="1565" x-info="http://www.rsyslog.com"] (re)start
Sep 19 09:47:36 localhost firefox: gethostby*.getanswer: asked for "vod.lzu.edu.cn.localdomain", got "wx.redirect.local"
Sep 19 09:47:36 localhost firefox: gethostby*.getanswer: asked for "vod.lzu.edu.cn", got "wx.redirect.local"
Sep 19 11:47:51 localhost kernel: npviewer.bin[7338] general protection ip:116f57c sp:bfddc9c0 error:0 in libflashplayer.so[dfd000+994000]
Sep 19 11:48:10 localhost firefox: gethostby*.getanswer: asked for "vod.lzu.edu.cn", got "wx.redirect.local"
Sep 19 11:49:25 localhost firefox: gethostby*.getanswer: asked for "vod.lzu.edu.cn", got "wx.redirect.local"
Sep 19 11:49:25 localhost firefox: gethostby*.getanswer: asked for "vod.lzu.edu.cn", got "wx.redirect.local"
Sep 19 12:28:35 localhost kernel: npviewer.bin[15863] general protection ip:116f57c sp:bfd1c2c0 error:0 in libflashplayer.so[dfd000+994000]


主要是需要指定处理的日志,开始和结束的时间,指定的字符串,检查这段时间内的日志中是否存在某一个指定的字符串,返回值为真或者假就可以。我是新手,不清楚怎么处理时间这段,各位能帮忙的就麻烦您帮个忙。

论坛徽章:
0
2 [报告]
发表于 2010-09-19 16:45 |只看该作者
发一段伪代码:
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;


  4. sub checktime(){
  5.     #用这个函数来检查时间是否在范围内,如果是、返回1,如果不是返回0
  6.     #具体比较因为需求不太明朗,这里留空,请自行补充,呵呵
  7. }

  8. my $flag = 'false';
  9. open FH,"< 日志文件路径";
  10. while(<FH>){
  11.     my $line = $_;
  12.     if($line =~ /^(.+?:\d\d:\d\d)/){
  13.         my $result = &checktime($1);  #这里$1里存放的就是时间,如:Sep 19 12:28:35
  14.         if($result > 0 && $line =~ /关键字/){
  15.             $flag = 'true';
  16.             next;
  17.         }
  18.     }
  19. }
  20. close FH;
  21. return $flag;
复制代码

论坛徽章:
0
3 [报告]
发表于 2010-09-20 09:09 |只看该作者
{:3_200:}谢谢指点
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP