So, I want to launch a shell command through tmux, but in the background and detaching from said tmux session...so I do it like so:
tmux new-session -A -s myprogramsession \; send -t myprogramsession "nohup /usr/bin/myscript.sh &>/dev/null &" ENTER \; detach -s myprogramsession
This works. But now, if I want to make tmux stop once it detached from the aforementioned session, I would need to either do:
this:
tmux new-session -A -s myprogramsession \; send -t myprogramsession "nohup /usr/bin/myscript.sh &>/dev/null &" ENTER \; detach -s myprogramsession \; kill-session -t myprogramsession
or this:
tmux new-session -A -s myprogramsession \; send -t myprogramsession "nohup /usr/bin/myscript.sh &>/dev/null &" ENTER \; detach -s myprogramsession && pkill tmux
While both methods (one using pkill
and kill-session
from tmux
) seems to work on first glance, I noticed both prevent the process/script launched through nohup
from staying in the background, compared to the first attempt which manage to do so (minus for the part about stopping tmux
).
How could I make tmux
(based on the above examples) launch a shell command on a session (in the background), detach it, then stop tmux
completely while the shell command is still running in the background?
P.S.: I did check through this and this post, but failed to find a solution there.
tmux
for? To kill it right away? What's the point?run-shell
as a replacement ofsend-keys
.