Created
May 5, 2014 18:24
-
-
Save prashanthrajagopal/27cbcddcd26ecef95e40 to your computer and use it in GitHub Desktop.
Persistent Interactive SSH connection to multiple servers
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 | |
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