Created
May 12, 2011 00:43
-
-
Save SeanPlusPlus/967707 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# | |
# tmuxConnect SessionName FileWithMachineNames | |
# | |
# pass a file with a list of machine names as a parameter to this script | |
# and it will open a new tmux session with a window ssh'd into each host | |
SESSION=$1 | |
MACHINE_FILE=$2 | |
function usage | |
{ | |
msg="USAGE: tmuxConnect SessionName FileWithMachineNames" | |
if [ "$SESSION" = "" ] | |
then | |
echo $msg; exit 1; | |
fi | |
if [ ! -e $MACHINE_FILE ] | |
then | |
echo $msg; exit 1; | |
fi | |
} | |
function newTmuxSession | |
{ | |
tmux new-session -d -s $SESSION | |
tmux rename-window -t $SESSION:0 ADMIN | |
} | |
function populateTmuxSession | |
{ | |
declare -a machine | |
i=0 | |
while read line ; do | |
machine[$i]=${line} | |
tmux new-window -t $SESSION -n ${machine[$i]} "ssh ${machine[$i]}" | |
i=$(($i+1)) | |
done < $MACHINE_FILE | |
tmux attach -t $SESSION | |
} | |
function main | |
{ | |
usage | |
newTmuxSession | |
populateTmuxSession | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment