如何在创建新的分离会话时告诉 tmux 以在之后发出另一个 tmux 命令

How to tell tmux when creating a new detached session to issue afterwards another tmux command

在我的正常 shell 中,我在后台为 运行 创建 tmux 会话

tmux new-session -d -s my-session my-script.sh (1)

现在我想通过 pipe-pane 将所有输出的日志记录添加到会话中。我知道如何在 not 分离会话中执行此操作(在 inside tmux 中):

Ctrl-B : pipe-pane -o 'cat >>~/tmp/output.log' (2)

但是我如何告诉 tmux 在创建分离会话时 - 通过 (1) - 立即添加 pipe-pane tmux 命令?

我基本上在我的正常 shell 中寻找一种方法来创建带有日志记录的分离 tmux 会话。 - 我正在使用 tmux 1.6。

你总是可以将这两个命令组合成一个 tmux 命令(我没有 tmux 1.6 来测试它,但它适用于 2.2):

tmux new-session -d -s my-session my-script.sh \; pipe-pane -o 'cat >>~/tmp/output.log'

如果您使用的是 tmux 2.9 或更高版本,则可以在新会话启动时设置一个挂钩 运行 命令。放入你的 ~/.tmux.conf

set-hook -g session-created "pipe-pane -o 'cat >>~/tmp/output.log'"

为了应对许多会话,您可以在文件名中包含会话名称,例如output.#{session_name}.log.