-
-
Save sourcesimian/8ca8a32b397bef19ecceeb330f6e43a9 to your computer and use it in GitHub Desktop.
Light weight MoSH using Tmux and BASH
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 | |
# 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