zoukankan      html  css  js  c++  java
  • Perl 打印关键字上下行

    #!/usr/bin/perl 
    $dir  = '/home/mysql';
    $file = '1.log';
    $mon_file = "$dir/$file";
    print "$mon_file is $mon_file
    ";
    @warn_arr = qw/连接已关闭 连接超时 NullPointException IndexOutOfBound exception/;
    foreach $a (@warn_arr) {
        undef @err_info;
        open( C, "<", "$a.tmp" );
        while (<C>) {
            $count = $_;
        }
        print "$a is $count";
    
        open( A, "<", "$mon_file" ) || die "$!
    ";
        $i   = 0;
        $num = 0;
        while (<A>) {
            $num++;
            if ( $_ =~ /$a/i ) { $i++; $b = $num }
        }
        print "$b is $b
    ";
    
        if ( $i != 0 && $i != $count && defined($count) ) {
            open( B, "<", "$mon_file" ) || die "$!
    ";
            while (<B>) {
                chomp($_);
                push( @err_info, $_ ) if ( $. >= $b - 5 and $. <= $b + 5 );
            }
            print "@err_info is @err_info
    ";
            system("SMSsendx  111111111 "@err_info" 10.10.10.10");
        }
    
        open( C, ">", "$a.tmp" );
    
        print C ("$i
    ");
    
    }

  • 相关阅读:
    SimpleXML简单使用
    制作RSS供应源
    DOM方式操作XML
    Referer与图片防盗链
    PAT
    Margarite and the best present
    Petya and Origami
    Margarite and the best present
    Petya and Origami
    A/B
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351743.html
Copyright © 2011-2022 走看看