ssh-tmux:以编程方式使用ssh执行长时间运行的命令

ssh-tmux:以编程方式使用ssh执行长时间运行的命令,ssh,tmux,Ssh,Tmux,我需要在远程服务器上以编程方式执行长时间运行的脚本。我尝试将ssh与screen或tmux一起使用,但到目前为止,我无法使其正常工作 使用tmux,在本地机器终端键入ssh命令时,我成功地使其工作: ssh <server_name> -t -t tmux new -s my_session \; set-buffer "bash my_script.sh" \; paste-buffer \; send-keys C-m \; detach ssh-t-ttmux new-s m

我需要在远程服务器上以编程方式执行长时间运行的脚本。我尝试将ssh与screen或tmux一起使用,但到目前为止,我无法使其正常工作

使用tmux,在本地机器终端键入ssh命令时,我成功地使其工作:

ssh <server_name> -t -t tmux new -s my_session \; set-buffer "bash my_script.sh" \; paste-buffer \; send-keys C-m \; detach
ssh-t-ttmux new-s my_session\;设置缓冲区“bash my_script.sh”\;粘贴缓冲区\;发送密钥C-m\;拆卸
但如果以编程方式运行此操作,则会出现以下错误:

open terminal failed: missing or unsuitable terminal: unknown
Connection to <server_name> closed
打开终端失败:缺少或不合适的终端:未知
连接到已关闭

使用-d标志启动新会话以启动tmux。因此:

ssh <server_name> tmux new -ds my_session \; send-keys "bash my_script.sh" C-m

ssh-tmux-new-ds my_session\;发送键“bash my_script.sh”C-m

“如果我以编程方式运行此命令…”请将您的问题包括在用于调用命令的代码中。它似乎正在工作。非常感谢。