-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyssh
executable file
·75 lines (49 loc) · 1021 Bytes
/
myssh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env perl
use strict;
use List::MoreUtils;
use Tie::IxHash;
use local::lib '~/bin';
use MySSH;
#use Data::Dumper;
#die Dumper(\%INC);
my @sshstr;
sub gethosts {
List::MoreUtils::natatime 2, @MySSH::user;
}
sub printchoices {
print "\n\n";
print "ssh hosts\n";
print "---------\n";
my $iterator = gethosts;
my $i;
while (my ($user,$host) = $iterator->()) {
my $sshstr = sprintf '%s@%s' , $user, $host;
printf "[%d] %s\n", $i++, $sshstr;
push @sshstr, $sshstr;
}
}
sub prompt {
print "\n\nssh to: " ;
}
sub getchoice {
prompt ;
my $choice = <STDIN> ;
chomp $choice;
return $choice;
}
sub mainloop {
{
printchoices;
my $c = getchoice ;
return $c if $c =~ /^\d+$/ and $c >= 0 and $c <= $#MySSH::user ;
redo;
}
}
my $choice = mainloop;
my $sshstr = $sshstr[$choice];
print $sshstr, "\n" ;
if ($ENV{DISPLAY}) {
system "xterm -title '$sshstr' -e 'ssh -Y $sshstr' &" ;
} else {
exec 'ssh', '-A', '-X', $sshstr, '&' ;
}