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
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.
Ctrl+b, let go of Ctrl, Letf / Right / Up / Down will switch active panes.
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>
For tmux version 2.1 this works
tmux a -t <session-name> \; select-window -t <windowID> \;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With