Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tmux - attach to a session and specify window

I have a script (.sh) and I want it to run in a existing tmux session. I have 1 session with 8 windows in.

Is there a command like tmux a -t session-name, which also specify the window?

And would a script like this work?

#!/bin/bash tmux a -t session-name #What ever to write to specify window# java -jar -Xmx4G -Xms4G Spigot.jar

like image 747
user3707440 Avatar asked Jun 07 '14 19:06

user3707440


People also ask

How do I add a window to tmux?

You can also access a tmux command line and type tmux commands by name. For example, to create a new window the hard way, you can press Ctrl+B followed by : to enter the tmux command line. Type new-window and press Enter to create a new window. This does exactly the same thing as pressing Ctrl+B then C.

How do I change windows in tmux?

Ctrl+b, let go of Ctrl, Letf / Right / Up / Down will switch active panes.


2 Answers

You can change the active window of a session before you attach to the session.

tmux -t <session-name> select-window -t <windowID>
tmux a -t <session-name>

You can combine two tmux commands as well.

tmux -t session-name select-window -t <windowID> \; a

If you really want to run java, presumably you want to create a new window with new-window, rather than select an existing one with select-window.


Newer versions of tmux (at least 1.9; did the above ever work, perhaps in 1.6?) no longer appear to have a -t option to specify the session to apply commands to. Instead, each individual command specifies the session.

tmux select-window -t <session-name>:<windowID> \; a -t <session-name>
like image 158
chepner Avatar answered Sep 19 '22 19:09

chepner


For tmux version 2.1 this works

tmux a -t  <session-name> \; select-window -t <windowID> \;
like image 45
dowewas Avatar answered Sep 21 '22 19:09

dowewas