-
Notifications
You must be signed in to change notification settings - Fork 6
/
ssh
executable file
·46 lines (37 loc) · 944 Bytes
/
ssh
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
#!/usr/bin/perl
# Just a wrapper to setup remote dir
# The way this works is store a magic comment in
# the .ssh/config file which looks like this:
#
# host mybox
# #RemoteDir /some/dir
#
# This gets parsed and magicly added to the ssh
#
use strict;
use File::Basename;
my $cmd = join ' ', @ARGV ;
my $fh;
my $target = $ARGV[0];
my $filename = dirname(dirname($0)) . '/.ssh/config';
if ($#ARGV eq 0 and open($fh, '<:encoding(UTF-8)', $filename)) {
my $host = '';
my $match = '';
while (my $row = <$fh>) {
chomp $row;
if ($row =~ /^host (.*)/i){
$host = " $1 ";
if ($host =~ /\s$target\s/) {
$match = $host;
} else {
$match = '';
}
}
if ($match and $row =~ /RemoteDir (\S*)/i){
$cmd = "-t $target \"cd $1; bash -l\"";
}
}
}
$cmd = "/usr/bin/ssh $cmd";
# print "$cmd \n";
exec($cmd);