Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- my $filename = '~/.ssh/config';
- open(my $fh, '<:encoding(UTF-8)', $filename)
- or die "Could not open file '$filename' $!";
- my @hosts = ();
- while (my $row = <$fh>) {
- chomp $row;
- my ($host) = $row =~ /^Host (.*)$/;
- if ($host) {
- my $arraySize = @hosts;
- print "$arraySize: $host\n";
- push(@hosts,$host);
- }
- }
- my $userinput;
- if (defined $ARGV[0]) {
- $userinput = $ARGV[0];
- } else {
- $userinput = <STDIN>;
- chomp ($userinput);
- }
- my $host = $hosts[$userinput];
- if ( defined $host ) {
- print "ssh: $host\n";
- system("ssh", $host);
- } else {
- print "no host for $userinput\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement