-
-
Save mariow/5169873 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
my $ssh=`which ssh`; | |
my $mosh=`which mosh`; | |
chomp($ssh); | |
chomp($mosh); | |
my $host; | |
my $unsupported=0; | |
for (my $i=0; $i <= $#ARGV; $i++) { | |
if ($ARGV[$i] =~ /^-/) { | |
$ssh .= " \"$ARGV[$i]\""; | |
if ( grep { /$ARGV[$i]/ } ("-A","-C","-D","-e","-f","-g","-L","-M","-N","-n","-R","-V","-W","-w","-X","-Y") ) { | |
print "mosh does not support ssh's \"$ARGV[$i]\" option.\n"; | |
$unsupported=1; | |
} | |
if ( grep { /$ARGV[$i]/ } ("-b","-c","-D","-e","-F","-I","-i","-L","-l","-m","-O","-o","-p","-R","-S","-W","-w") ) { | |
$ssh .= " \"$ARGV[$i+1]\""; | |
$i++; | |
} | |
} else { | |
$host=$ARGV[$i]; | |
} | |
} | |
# mosh doesn't for dntx at the moment | |
if ($host =~ /us-east1.dntx.com/) { | |
print "Unsupported host\n"; | |
$unsupported = 1; | |
} | |
if (!$unsupported) { | |
# try running mosh | |
my $retval = system("$mosh --ssh='$ssh' $host"); | |
$retval = $retval >> 8; | |
if ($retval == 127) { $unsupported = 1; } | |
} | |
if ($unsupported) { | |
print "Falling back to ssh...\n"; | |
exec("$ssh $host"); | |
} |
Siehe mein Fork https://gist.github.com/moeffju/5170039 - system() gibt den Exit-Code in den oberen acht Bits zurück, du musst also 8 Bit nach rechts shiften.
Stimmt, viel eleganter - hab ich direkt mal so übernommen :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modified to support multiple failure return codes (mosh seems to quit with 32512 on OSX)