现象描述:
执行如下脚本内容时,脚本可以输出,但会提示TERM environment variable not set.
[root@test2 ~]# cat 2.sh #!/bin/bash ssh root@192.168.137.16 "bash /root/test/1.sh" [root@test2 ~]# sh 2.sh 111 TERM environment variable not set.
可能原因:
应该是对端机器的1.sh的问题
定位思路:
查看1.sh
[root@localhost test]# cat 1.sh #!/bin/bash clear echo "111"
echo肯定没问题,问题应该在clear上
解决方法:
1.如果不需要,可注释clear
[root@localhost test]# cat 1.sh #!/bin/bash #clear echo "111"
输出:
[root@test2 ~]# sh 2.sh 111
说明:加了clear的脚本在本机处理也不会有问题,但是在对端机器通过ssh远程执行就会有TERM environment variable not set的提示,原因是:clear本身需要TERM环境,在本机执行脚本时,本机是有TERM的,但ssh命令本身是不带TERM环境的,所以会报此提示。
[root@localhost test]# set |grep term TERM=xterm
2.若不能注释clear,则需要定义变量
[root@localhost test]# cat 1.sh #!/bin/bash export TERM=xterm clear echo "111"
再次远程执行2.sh脚本
[root@test2 ~]# sh 2.sh root@192.168.137.16's password: 111