Last active
August 29, 2015 13:57
-
-
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 ..."
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 | |
# | |
# 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