this has probably been done before and it's not that clever. but i find it useful - it saves me adding aliases to .bashrc for machines i commonly ssh to:
This goes in a directory which is added to my path, and then gets symlinked to. the name of the symlink being the target machine, or an abbreviation of it.
This goes in a directory which is added to my path, and then gets symlinked to. the name of the symlink being the target machine, or an abbreviation of it.
so now typing box1 will ssh me to that machine (i then also obv get tab completion on machine names)# ls ssh-targets: ssh.pl box1 -> ssh.pl box2 -> ssh.pl
#!/usr/bin/perl my $file=$0; # what machine are we looking at? $file=~s#^(?:.*/)?([^/]+)$#$1#; my $dest; # a config hash for expanding the name, and choosing the user. my $places={ box=>{full=>"boxwithlongname"}, home=>{full=>"blahblah",user=>"alexk"} }; # if i have many machines with the same long name - abbreviate to box # (as in hash above), so box1 goes to boxwithlongname1 etc my ($short,$number)=$file=~/^(\D+)(\d?)$/; my $hash=$places->{$short}; $dest=$hash->{full}?$hash->{full}.$number:$file; $user=$hash->{user}||"alex"; # and ssh to it. exec("ssh $user\@$dest @ARGV") if $dest;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: ssh wrapper
by tirwhan (Abbot) on Mar 28, 2006 at 10:29 UTC | |
by teamster_jr (Curate) on Mar 28, 2006 at 10:33 UTC | |
Re: ssh wrapper
by radiantmatrix (Parson) on Mar 28, 2006 at 18:33 UTC |
Back to
Cool Uses for Perl