找到正確的 tmux 發送金鑰到自訂套接字和會話語法

找到正確的 tmux 發送金鑰到自訂套接字和會話語法

我試圖使發送鍵參數的語法正確,並嘗試了一些我試圖從手冊頁中拼湊出來的變體,但我一定只是誤解了某些東西。

我按以下方式初始化 tmux 並希望對其進行操作,如下所示。

sudo -H -u username1 -g usergroup1 bash -c '/usr/bin/tmux -S /home/shares/tmux_sessions/sock_file new -d -s "sess-tv0-i" mycommand -arg1 -arg2'
sudo -H -u username1 -g usergroup1 bash -c '/usr/bin/tmux -S /home/shares/tmux_sessions/sock_file new -d -s "sess-tv1-i" mycommand -arg1 -arg2'
sudo -H -u username1 -g usergroup1 bash -c '/usr/bin/tmux -S /home/shares/tmux_sessions/sock_file new -d -s "sess-tv2-i" mycommand -arg1 -arg2'

我嘗試將金鑰傳送到單一會話,但是下面的命令似乎會將命令傳送到所有會話,這是不需要的,我希望一次只將金鑰傳送到 1 個會話。

tmux -S /home/shares/tmux_sessions/sock_file send-keys C-c -t sess-tv0-i

使用上面的命令不會給出錯誤,但是如上所述,它確實將該密鑰字串發送到該套接字中的多個會話。

我也嘗試過以下方法但失敗。

tmux -S /home/shares/tmux_sessions/sock_file target-session -t sess-tv0-i send-keys C-c
unknown command: target-session

tmux target-session -t sess-tv0-i send-keys C-c
error connecting to /tmp/tmux-0/default (No such file or directory)

tmux -S /home/shares/tmux_sessions/sock_file -t sess-tv0-i send-keys C-c
tmux: unknown option -- t
usage: tmux [-2CluvV] [-c shell-command] [-f file] [-L socket-name]
            [-S socket-path] [command [flags]]

感謝您的任何建議或為我指明正確的方向。

答案1

使用時出現明顯錯誤

tmux -S /home/shares/tmux_sessions/sock_file send-keys C-c -t sess-tv0-i

這會將 Cc 或 Control+c 鍵傳送到該 sock 檔案中的所有會話,而不是使用

tmux -S /home/shares/tmux_sessions/sock_file send-keys -t sess-tv0-i C-c

這允許正確評估 -t 標誌。

相關內容