Skip to content

Instantly share code, notes, and snippets.

@SeanPlusPlus
Created May 12, 2011 00:43
Show Gist options
  • Save SeanPlusPlus/967707 to your computer and use it in GitHub Desktop.
Save SeanPlusPlus/967707 to your computer and use it in GitHub Desktop.
#!/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