Skip to content

Instantly share code, notes, and snippets.

@prashanthrajagopal
Created May 5, 2014 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prashanthrajagopal/27cbcddcd26ecef95e40 to your computer and use it in GitHub Desktop.
Save prashanthrajagopal/27cbcddcd26ecef95e40 to your computer and use it in GitHub Desktop.
Persistent Interactive SSH connection to multiple servers
#!/bin/bash
set -e
###############################################
### Add this to your ~/.ssh/config #
### ControlPath ~/.ssh/master-%r@%h:%p #
### ControlMaster no #
### Run this as ./persistent_ssh.sh box1 box2 #
###############################################
MY_PROMPT="$ "
for arg in "$@"
do
eval "ssh -MNf $arg"
done
while :
do
echo -n "$MY_PROMPT"
read line
for server in "$@"
do
echo "------------------------"
echo "$server : "
echo "------------------------"
eval "ssh $server \"$line\""
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment