Guest User

Untitled

a guest
May 25th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. use warnings;
  2. use strict;
  3.  
  4. use Getopt::Long;
  5.  
  6. my ($search, $sfilename);
  7.  
  8. GetOptions(
  9. 'search=s' => \$search,
  10. 'servers=s' => \$sfilename,
  11. );
  12.  
  13. $sfilename ||= 'servers';
  14. $search ||= $ARGV[0] or die 'You need to search for something.';
  15.  
  16. my $regex = eval { qr{$search} } or die "invalid regex: $search";
  17.  
  18. open my $sfile, '<', $sfilename or die "$sfilename: $!";
  19. while (my $host = <$sfile>) {
  20. chomp $host;
  21. print "Searching $host...\n";
  22.  
  23. open my $search, '-|', "ssh $host ls /data/WebGUI/etc/*.conf"
  24. or die "problem connecting to $host";
  25.  
  26. while (my $line = <$search>) {
  27. my ($site) = $line =~ qr{^/data/WebGUI/etc/(.*).conf};
  28. if ($site =~ $regex) {
  29. print "...$site is on $host. Keep looking? (y/n) ";
  30. my $answer = <STDIN>;
  31. chomp $answer;
  32. if ($answer !~ /^[Yy]/) {
  33. close $search;
  34. close $sfile;
  35. exit 0;
  36. }
  37. }
  38. }
  39. close $search;
  40. }
  41. close $sfile;
  42.  
  43. print "Not found.\n";
  44. exit 1;
Add Comment
Please, Sign In to add comment