shell tmux打开终端失败:不是终端

dwbf0jvd  于 2023-08-07  发布在  Shell
关注(0)|答案(3)|浏览(183)

我有一个shell脚本,作为服务启用,以启动多个shell脚本,例如。

service started script -> script1, script2 ,script3

字符串
script1应该在tmux窗口中打开一个程序,如果我通过./script1.sh手动启动脚本,它确实工作得很好,但是当通过服务启动脚本在 Boot 时启动时,它不会出现上述错误:

open terminal failed: not a terminal


为什么会这样?

3df52oht

3df52oht1#

已经有一个答案here,但我认为this link更好地总结了它。简单地说,使用-t标志:

ssh -t host tmux attach

字符串
如果您想将其设置到.ssh/config文件中,请在ssh_config手册页中查找RequestTTY选项:

RequestTTY
         Specifies whether to request a pseudo-tty for the session.  The
         argument may be one of: ``no'' (never request a TTY), ``yes''
         (always request a TTY when standard input is a TTY), ``force''
         (always request a TTY) or ``auto'' (request a TTY when opening a
         login session).  This option mirrors the -t and -T flags for
         ssh(1).

x6492ojm

x6492ojm2#

我认为问题是该服务没有关联的tty。我发现的一个变通方法是将脚本中的tmux调用更改为

tmux new-session -s username -d

字符串
(username为其启动服务的用户)

sy5wg1nm

sy5wg1nm3#

如果您使用p10k作为zsh主题,如这里所述,您应该将此节放在.zsrc的顶部:

if [ -z "$TMUX" ]; then
  exec tmux new-session -A -s workspace
fi

字符串

相关问题