Skip to content

Instantly share code, notes, and snippets.

@sourcesimian
Created June 10, 2016 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sourcesimian/8ca8a32b397bef19ecceeb330f6e43a9 to your computer and use it in GitHub Desktop.
Save sourcesimian/8ca8a32b397bef19ecceeb330f6e43a9 to your computer and use it in GitHub Desktop.
Light weight MoSH using Tmux and BASH
#! /bin/bash
# usage: tssh <host> <tmux target> [<ssh args>]
# requires ssh passwordless login to be setup and tmux to be installed on the remote machine
host=$1
target=$2
args=${*:3}
ssh="ssh -o ConnectTimeout=4 -o ServerAliveInterval=4 -o ServerAliveCountMax=2 -o TCPKeepAlive=yes"
if [ ! -z $target ]; then
cmd="tmux attach-session -t '$target' || tmux new-session -s '$target'"
else
cmd="tmux attach-session || tmux new-session"
fi
while true; do
if $ssh "$host" $args -t "$cmd"; then
break
fi
echo
echo "Connection to \"$host\" dropped ..."
while ! ping -c 1 -t 3 "$host" >/dev/null 2>&1; do
sleep 10
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment