Skip to content

Instantly share code, notes, and snippets.

@SteveCooling
Last active August 29, 2015 13:57
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 SteveCooling/9547921 to your computer and use it in GitHub Desktop.
Save SteveCooling/9547921 to your computer and use it in GitHub Desktop.
Simple tool to automate running commands in parallell using tmux. Acts like clusterssh when invoked like this:"tmulti.sh ssh host1 host2 ..."
#!/bin/bash
#
# Author: Morten Johansen <morten@cerum.no>
# License: CC BY-SA 3.0 http://creativecommons.org/licenses/by-sa/3.0/
# Usage: tmulti <cmd> <arg1> ...
# Will create one pane in tmux for each arg, and execute "<cmd> <argN>" in each pane, in parallel
# Example: tmulti ssh user@node{1..4}.example.com
#
BNAME=$(basename ${0})
SESSION=$BNAME-$RANDOM
CMD=$1
if [ -z ${TMUX} ]
then
# Not inside tmux from before
tmux new-session -d -s "$SESSION" "$CMD $2"
tmux select-window -t "$SESSION:0"
else
# Already inside tmux.
tmux send-keys C-c
tmux send-keys "$CMD $2" C-m
fi
tmux rename-window "$BNAME $CMD"
for i in "${@:3}"
do
tmux split-window -h "$CMD $i"
tmux select-layout tiled
done
tmux set-window-option synchronize-panes on
if [ -z ${TMUX} ]
then
tmux attach-session -t "$SESSION"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment