Skip to content

Instantly share code, notes, and snippets.

@frodwith
Created May 7, 2010 17:40
Show Gist options
  • Save frodwith/393759 to your computer and use it in GitHub Desktop.
Save frodwith/393759 to your computer and use it in GitHub Desktop.
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