Have you ever needed to run the same command, on multiple servers? I've used cssh and pssh with great success in the past but tmux incorporates the parallelism features, including the features of another old school tool, screen.
I use this tool when teaching RH436L Red Hat High Availability Clustering, as we have to run the same commands on various nodes without using ansible.
Let's install tmux:
yum install -y tmux
Let's run tmux now:
tmux
You should see your terminal window with a horizontal green bar at the bottom:
All tmux commands begin with the prefix ^b (control b) so enter the prefix following by.a command:
I need to monitor the output of top of 4 servers, node[abcd] and look at the output in a single window so what I'm going to do is take my current window and split it horizontally using the command ^b "
We call these elements "panes". Note that my cursor is in the bottom pane.
Now I want to take the pane where my cursor is, and split it vertically using the command ^ b %
My cursor is automatically positioned to be in the bottom right pane.
Next, we want to move the cursor to the top pane, and then split that vertically. To move your cursor around the panes use ^ b o and then use ^ b % to split the top pane vertically.
Now I can use ^ b o to move my cursor around the various panes, and ssh into the nodes I want to run commands on.
To synchronize the commands from one pane, to all the other panes use ^ b :setw synchronize-panes on
You will see the command at the bottom left corner of your tmux window.
Now run your command, I've run top, and it will replicate your keystrokes across all panes.
To turn pane synchronization off, use ^ b :setw synchronize-panes off
Summary of commands (the prefix ^b is implied):
% create a veritcal split
" create a horizontal split
o move cursor between panes
x close a pane
:setw synchronize-panes on turn on pane synchronization
:setw synchronize-panes off turn off pane synchronization
d detach from a tmux session (like ^ a d in screen)
To reattach, use tmux a when you next login.
Awesome article!
I use tmux every day, and pane syncronization really helped me get through many Red Hat exams.
Small addition from my side - put lines below to your .tmux.conf file:
# Toggle synchronization
bind e setw synchronize-panes on
bind E setw synchronize-panes off
Now press:
<prefix>+e to enable syncronize panes
<prefix>+E to disable
Also, for anyone interested, consider spending some time reading the Tao of Tmux
Thanks for sharing these tips, with zero effort ;-) I can do them!
CTRL + B + " Horizontal
CTRL + B + % Vertical
setw -g mouse-select-pane on
setw -g mouse-select-window on
setw synchronize-panes on
Scroll in TMUX
ctrl +b + [ (courtesy Mithun from Mauritius for sharing)
Despite what man page of tmux, and this guide says it should work, Ctrl-b-" does not work if I am not into graphical target. I tried to run tmux on CentOS 7.6 Minimal in multiuser target, installs and starts fine except for when I actually try to split screen by Ctrl-b-", it waits for me to input some kind of index, and fails to acknowledge as a valid index anything I put in.
HEAVY EDIT: It wants you to press Ctrl-b, release, and then " (or other commands)... now that I found that detail out, it works (after glancing at somebody else's blog on tmux).
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.