我有一个 bash 脚本,它在运行时连续输出一些信息。我需要
为此,我想使用 tmux。那么我该如何处理呢?为简单起见,假设我的 shell 脚本是这样的:
文件名:start.bash
#!/bin/bash
# just an example for simplicity
watch date
Run Code Online (Sandbox Code Playgroud)
我需要另一个在 tmux 中运行它的脚本,并且可以在以后需要时附加到它。我在需要创建一个带有名称的新 tmux 会话并使其运行另一个 shell 脚本的部分苦苦挣扎。一旦我有了这个工作,我就可以把它放在另一个 shell 脚本中并处理其余的东西。这很容易,我想。有人可以给我一个这个特定步骤的例子吗?
您可以通过多种方式做到这一点。
您可以在使用发送密钥创建会话后执行此操作:
tmux new -s "remote" -d
tmux send-keys -t "remote" "start.bash" C-m
tmux attach -t "remote" -d
Run Code Online (Sandbox Code Playgroud)
或者通过shell:
tmux new -s "remote" -d "/bin/bash"
tmux run-shell -t "remote:0" "start.bash"
tmux attach -t "remote" -d
Run Code Online (Sandbox Code Playgroud)