Starting a new tmux session and detaching it, all inside a shell script Starting a new tmux session and detaching it, all inside a shell script unix unix

Starting a new tmux session and detaching it, all inside a shell script


Start a shell, and send vagrant up to it, so you can see the errors.

tmux new-session -d -s rbt123tmux send-keys 'vagrant up' C-mtmux detach -s rtb123

The C-m means hit return.


You are using the -d switch when creating the session. This means that the session will start detached, so you don't need to use the detach command. Besides, if your session is not running when you try to detach, it means that it no longer exists, so your command probably exited.


New, detached, named and with command executed in default shell:

tmux new-session -d -s apiserver 'java -cp /root/apiserver.jar com.package.EntryPoint'

To attach use:

tmux attach-session -t apiserver