Linux 批处理模式 SSH 给出错误“未设置 TERM 环境变量”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10063499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:40:09  来源:igfitidea点击:

Batch mode SSH gives error "TERM environment variable not set"

linuxssh

提问by YoramW

I made sure that TERM was defined in the .bashrc.

我确保在 .bashrc 中定义了 TERM。

However, when running ssh in batch mode I get:

但是,当以批处理模式运行 ssh 时,我得到:

 $ ssh pc-lab7 "echo $TERM; echo 
 -t      Force pseudo-tty allocation.  This can be used to execute arbitrary
         screen-based programs on a remote machine, which can be very useful,
         e.g. when implementing menu services.  Multiple -t options force tty
         allocation, even if ssh has no local tty.
" TERM environment variable not set. linux -bash

If I run ssh in interactive mode, I do not see this error.

如果我以交互模式运行 ssh,则不会看到此错误。

How can I eliminate this error message?

如何消除此错误消息?

回答by YoramW

I finally found the reason for this annoying "TERM environment variable not set" warning.

我终于找到了这个烦人的“未设置 TERM 环境变量”警告的原因。

It turned out that when the ssh is executing in batch mode without an interactive user, a call to 'clear' command in a startup script will yield this error.

事实证明,当 ssh 在没有交互式用户的情况下以批处理模式执行时,在启动脚本中调用“清除”命令将产生此错误。

Commenting out the 'clear' line in the script fixed the issue for me.

注释掉脚本中的“clear”行为我解决了这个问题。

回答by Thamme Gowda

Use of -toption to ssh allocates tty

使用-tssh 选项分配 tty

##代码##