bash - 启动一个新的 tmux session 并分离它,所有这些都在一个 shell 脚本中

标签 bash shell unix vagrant tmux

我正在尝试创建一个新的 tmux session 并执行命令“vagrant up”。 “Vagrant up”需要 3 个多小时,所以我想分离 session ,以便稍后返回并通过附加回同一 session 来检查该命令的状态。

我遵循了 StackOverflow post 中指定的答案完成同样的任务。

我收到错误消息找不到 session 。这是我的代码:

    $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

最佳答案

启动一个 shell,并将 vagrant up 发送给它,这样你就可以看到错误。

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

C-m 表示回车。

关于bash - 启动一个新的 tmux session 并分离它,所有这些都在一个 shell 脚本中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33426159/

相关文章:

linux - 使用别名执行脚本

mysql - 从 db2 制作输出文件显示从 shell 脚本创建表的过程?

c - 在solaris上使用c语言的openssl问题

linux - 设置除/bin/sh 以外的 Linux shell 是否有问题?

linux - 巴什脚本 : Combining Permutations of Contents in a Directory

shell - 为 Mac 创建与我的 BAT 文件相同的 Shell 脚本

c - 从文件中读取一行并将其存储在变量中

bash - 将 sed 反向引用传递给 base64 命令

bash - 在 bash 中进行 Ascii/Hex 转换

linux - 如何使用 AWK 从 nginx 访问日志中收集 IP 和用户代理信息并确定它们的基本 IP 地址?