Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
Add Comment
Please, Sign In to add comment