LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   tmux sending commands to individual panes (http://www.linuxquestions.org/questions/linux-software-2/tmux-sending-commands-to-individual-panes-917821/)

casperdaghost 12-08-2011 08:53 PM

tmux sending commands to individual panes
 
So part of my job is to monitor may servers at once - check out my master plan, I am so close.
I split the terminal into twelve panes using tmux - and log into each one an tail the /var/log/messages in each pane.

hitting control -b o and typing ssh and tail -f into pane is getting tiring.

I have pushed the keys out so I can passwordless ssh to the servers.
I am just having trouble creating a script to automate my ssh logins and commands delivery - how do I issue the three commands to
each pane?

ssh casper@server1
sleep 30
tail -f /var/log/messages

each pane must ssh to a different server and tail that servers logs.

how do i issue commands to the individual panes in tmux?
Code:

#!/bin/bash
tmux split-window -v
sleep 5
tmux select-pane -t 0
tmux split-window -v
tmux select-pane -t 0
tmux split-window -v
tmux select-pane -t 0
tmux split-window -v
tmux select-pane -t 3
tmux split-window -v
tmux select-pane -t 3
tmux split-window -v
tmux select-layout even-vertical

#for ((i = 0 ; i < 5 ; i++))
for i in 0 2 4 6 8 10
do
tmux select-pane -t $i
tmux split-window -h
done


ThomasAdam 01-14-2012 05:29 PM

Use the synchronise-panes option.

-- Thomas Adam

casperdaghost 01-17-2012 09:57 PM

I kinda worked this out on my own.
This script will breakup the terminal into 8 seperate panes.
It sends a command to each pane via the send keys invocation.
You could just as easily send a tail -f /var/log/messages or a ssh casper@capser box or whatever.

mark my words - pretty soon you will all be using tmux - it is a productivity tool.

You have to open up a tmux session manually and then invoke the script.

Code:



#!/bin/bash

###this is going to split the pane into four
###even horizontal panes
tmux split-window -v
sleep 1
tmux send-keys -t 0 "clear" C-m
tmux select-pane -t 0

tmux split-window -v
sleep 1
tmux select-pane -t 3

tmux split-window -v
sleep 1
tmux select-pane -t 5

tmux split-window -v
tmux select-layout even-vertical

 
###this will split each of the four panes
###vertically, resulting in eight seperate
###panes

for i in 0 2 4 6
do
tmux select-pane -t $i
tmux split-window -h
sleep 1
done


this goes to each pane and sends a command, in this case - just identifies the pane.

tmux select-pane -t 0
tmux send-keys -t 0 "This is pane 0" C-m
tmux select-pane -t 1
tmux send-keys -t 1 "This is pane 1" C-m
tmux select-pane -t 2
tmux send-keys -t 2 "This is pane 2" C-m
tmux select-pane -t 3
tmux send-keys -t 3 "This is pane 3" C-m
tmux select-pane -t 4
tmux send-keys -t 4 "This is pane 4" C-m
tmux select-pane -t 5
tmux send-keys -t 5 "This is pane 5" C-m
tmux select-pane -t 6
tmux send-keys -t 6 "This is pane 6" C-m
tmux select-pane -t 7
tmux send-keys -t 7 "This is pane 7" C-m
tmux select-pane -t 8
tmux send-keys -t 8 "This is pane 8" C-m



All times are GMT -5. The time now is 09:31 AM.