- 论坛徽章:
- 0
|
本帖最后由 zhlong8 于 2012-09-13 21:48 编辑
使用perl编写一个脚本,用于查找目录下的所有文件,且文件内容包含一个IP:192.168.2.99的,均把文件名输出,此脚本如有徐太的,把一些过滤参数更改一些即可:
#!/usr/bin/perl -w
use strict;
use File::Find;
my $source;
my $strings;
sub wanted {
##Check to see if the filename is not a directory.###
if ( -f $File::Find::name ) {
##### verify the filename is "database.xml"###
if ( $File::Find::name =~/database.xml$/ ) {
$source=$File::Find::name;
open(PH,$source) || die "Cannot open $source:$!";
####reading every line###
while(<;PH>;) {
$strings=$_;
if (m/192.168.2.99/i) {
print "$source\n";
}
}
}
}
}
find (\&wanted,"/usr/local/jboss-7.0.2GA/bin/conf");
写的不好,请各位大侠指点一下! |
|