Perl 打印关键字上下行
发布时间:2020-12-15 23:45:37 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/perl $dir = '/home/mysql';$file = '1.log';$mon_file = "$dir/$file";print "$mon_file is $mon_filen";@warn_arr = qw/连接已关闭 连接超时 NullPointException IndexOutOfBound exception/;foreach $a (@warn_arr) { undef @err_info; open
#!/usr/bin/perl $dir = '/home/mysql'; $file = '1.log'; $mon_file = "$dir/$file"; print "$mon_file is $mon_filen"; @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 "$!n"; $i = 0; $num = 0; while (<A>) { $num++; if ( $_ =~ /$a/i ) { $i++; $b = $num } } print "$b is $bn"; if ( $i != 0 && $i != $count && defined($count) ) { open( B,"$mon_file" ) || die "$!n"; while (<B>) { chomp($_); push( @err_info,$_ ) if ( $. >= $b - 5 and $. <= $b + 5 ); } print "@err_info is @err_infon"; system("SMSsendx 222221111 "@err_info" 10.10.10.10"); } open( C,">","$a.tmp" ); print C ("$in"); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |