Created
May 7, 2010 17:40
-
-
Save frodwith/393759 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use warnings; | |
use strict; | |
use Getopt::Long; | |
my ($search, $sfilename); | |
GetOptions( | |
'search=s' => \$search, | |
'servers=s' => \$sfilename, | |
); | |
$sfilename ||= 'servers'; | |
$search ||= $ARGV[0] or die 'You need to search for something.'; | |
my $regex = eval { qr{$search} } or die "invalid regex: $search"; | |
open my $sfile, '<', $sfilename or die "$sfilename: $!"; | |
while (my $host = <$sfile>) { | |
chomp $host; | |
print "Searching $host...\n"; | |
open my $search, '-|', "ssh $host ls /data/WebGUI/etc/*.conf" | |
or die "problem connecting to $host"; | |
while (my $line = <$search>) { | |
my ($site) = $line =~ qr{^/data/WebGUI/etc/(.*).conf}; | |
if ($site =~ $regex) { | |
print "...$site is on $host. Keep looking? (y/n) "; | |
my $answer = <STDIN>; | |
chomp $answer; | |
if ($answer !~ /^[Yy]/) { | |
close $search; | |
close $sfile; | |
exit 0; | |
} | |
} | |
} | |
close $search; | |
} | |
close $sfile; | |
print "Not found.\n"; | |
exit 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment