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

喜你入骨 提交于 2019-12-18 12:05:07

问题


I am trying to create a new tmux session and execute the command 'vagrant up'. 'Vagrant up' takes more than 3 hours so I want to detach the session so that I can come back later and check the status of that command by attaching back to the same session.

I followed the answer specified in the StackOverflow post to accomplish the same.

I am getting the error no session found. Here is my code:

    $cat tmux_sh.sh
    #!/bin/bash
    echo "step 1"
    tmux new-session -d -s rtb123 'vagrant up'
    echo "step 2"
    tmux detach -s rtb123

    $./tmux_sh.sh
    step 1
    step 2
    session not found: rtb123

回答1:


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

tmux new-session -d -s rbt123
tmux send-keys 'vagrant up' C-m
tmux detach -s rtb123

The C-m means hit return.




回答2:


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.



来源:https://stackoverflow.com/questions/33426159/starting-a-new-tmux-session-and-detaching-it-all-inside-a-shell-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!