Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my $filename = '~/.ssh/config';
  7. open(my $fh, '<:encoding(UTF-8)', $filename)
  8. or die "Could not open file '$filename' $!";
  9.  
  10.  
  11. my @hosts = ();
  12.  
  13. while (my $row = <$fh>) {
  14. chomp $row;
  15. my ($host) = $row =~ /^Host (.*)$/;
  16. if ($host) {
  17. my $arraySize = @hosts;
  18. print "$arraySize: $host\n";
  19. push(@hosts,$host);
  20. }
  21. }
  22.  
  23.  
  24. my $userinput;
  25.  
  26. if (defined $ARGV[0]) {
  27. $userinput = $ARGV[0];
  28. } else {
  29. $userinput = <STDIN>;
  30. chomp ($userinput);
  31. }
  32.  
  33. my $host = $hosts[$userinput];
  34.  
  35. if ( defined $host ) {
  36. print "ssh: $host\n";
  37. system("ssh", $host);
  38. } else {
  39. print "no host for $userinput\n";
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement