Score:0

How to start tmux session with 2 panes and execute in each pane predefined command, only then connect to this tmux session?

ca flag

I want to create development environment in docker and establish there tmux session where I can see 2 watch processes (frontend watch process and backend watch process).\

I can't seem to understand how to write bash script that will create tmux session with 2 panes with predefined commands.

I want to use tmux and not some kind of "virtual split log viewer" so I can restart process in each pane manually, because well sometimes we make mistakes in code that will just kill the build-watch process and it needs to be restarted.

Thank you in advance!

Score:0
ca flag

Here is one way to do this

tmux new -d -s my-session-name \; split-window -h ;\ 
tmux send-keys -t my-session-name.1 "here you can write any command for process that will attach to terminal and show output, like python manage.py runserver" ENTER
tmux send-keys -t my-session-name.2 "here you can write any command for process that will attach to terminal and show output, like python manage.py runserver" ENTER

# Use this to connect whenever you want 
tmux a -t my-session-name

In the end you will have tmux session with 2 panes and each pane will have process running and showing output.

To switch between panes use Ctrl-b o

NOTE: you see those numbers after my-session-name? Those are panes

Sometimes you gotta change those numbers from 1 and 2 to 0 and 1. Test it and if you see only last panes or no panes executing command - try to find numbers for your panes. I assume knowing people here can comment how to determine which pane will have which number.

For example on my host machine my panes are 1 and 2, and inside docker (debian) they are 0 and 1

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.