背景
需要使用ssh 远程别的服务器然后执行脚本,整理了遇到的错误。
脚本内容
#!/bin/bash
for ip in `cat /root/ip| awk '{print $1}'`
do
`ssh root@${ip} '/bin/bash test.sh'`
done
报错日志
ssh.sh: line 4: hello: command not found
ssh.sh: line 4: hello: command not found
ssh.sh: line 4: hello: command not found
ssh.sh: line 4: hello: command not found
ssh.sh: line 4: hello: command not found
一开始以为是ssh 执行脚本环境变量有问题
- https://www.cnblogs.com/zhenyuyaodidiao/p/9287497.html
- https://blog.csdn.net/whitehack/article/details/51705889
后来使用 ”echo $PATH"
发现环境变量是正常的
于是怀疑是 ``的问题
将` 去掉,重新执行
代码如下:
#!/bin/bash
for ip in `cat /root/ip| awk '{print $1}'`
do
ssh root@${ip} '/bin/bash test.sh'
done
执行成功!
总结
我这边遇到的问题并不是 环境变量的问题,而是 ` 符号的问题,这个记录一下。