Running commands in tmux windows when windows/panes are created

15 views Asked by At

I have a tmux session that has lot of windows and panes (for monitoring some tests) and once in a while when server is rebooted all of it is gone. I would like make it easy to recreate the whole tmux session by running a command in each of the split panes in specific windows (i.e. window X, pane Y run ssh and so on). I have wrapped the part where windows are split into panes in bash script and that part works. However, send-keys is not working when I try to send the command string to specific pane. I just need the command to be typed and ready in each pane (if I can run it without explicitly hitting Enter key, that is even better).

Can someone please help what I am missing here ?

#!/bin/bash
if [ $# -ne 1 ]; then
    echo "Usage: $0 <session-name>"
    exit 0
fi

session_name=$1
tmux new-session -d -s ${session_name}

tmux new-window -n test
tmux split-window -h
tmux split-window -v

# the following 3 lines don't work !!
tmux send-keys -t ${session_name}.test.0 'ls -1'
tmux send-keys -t ${session_name}.test.1 'cd results'
tmux send-keys -t ${session_name}.test.2 'top'                                                                                                                                                                                                                                                                                                         

tmux kill-window -t 1
tmux -2 attach-session -d

I see that it complains that "session test.test not found" when I run this script as

tmux-new-test test

Note that I don't want to send same command to all panes.

Thanks, SK

0

There are 0 answers