admin管理员组文章数量:1130349
现象描述:
执行如下脚本内容时,脚本可以输出,但会提示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
现象描述:
执行如下脚本内容时,脚本可以输出,但会提示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
版权声明:本文标题:shell脚本报:TERM environment variable not set 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1755498897a2762333.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论