-
-
Save vnys/c2f125f02acb04bef2ba 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
#!/bin/bash | |
# | |
# AutoSSH to host and create or connect to tmux session | |
# Multi-hop version. Separate hops with : | |
# | |
# Author: Oystein Steimler <[email protected]> | |
HLIST=$1; | |
IFS=':' read -a HOPS <<< "$HLIST" | |
AUTOSSHPRM="-M0 -o ServerAliveInterval=10 -o ServerAliveCountMax=2 -o BatchMode=yes" | |
CMD="if tmux ls | grep ^$2; then tmux att -t $2; else tmux new -s $2;fi"; | |
for ((i=${#HOPS[@]}-1; i>=1; i--)) | |
do | |
PCMD=$(printf %q "$CMD"); | |
CMD="if [ \`which autossh\` ] ; then echo AutoSSH; autossh $AUTOSSHPRM -t ${HOPS[$i]} $PCMD; else echo SSH; ssh -t ${HOPS[$i]} $PCMD; fi "; | |
done | |
#echo $CMD; | |
if [ `which autossh` ]; | |
then | |
echo AutoSSH; | |
autossh $AUTOSSHPRM -t ${HOPS[$i]} $CMD; | |
else | |
echo SSH; | |
ssh -t ${HOPS[0]} $CMD; | |
fi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment