Skip to content

Instantly share code, notes, and snippets.

@vnys
Forked from cybic/remux-hop
Last active August 29, 2015 14:16
Show Gist options
  • Save vnys/c2f125f02acb04bef2ba to your computer and use it in GitHub Desktop.
Save vnys/c2f125f02acb04bef2ba to your computer and use it in GitHub Desktop.
#!/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