【发布时间】:2014-03-20 09:51:12
【问题描述】:
此脚本从 hosts.txt 中读取系统 IP,登录系统,检查操作系统类型,执行一组命令并打印输出。
ssh 部分工作正常,但是在显示 'ls'' 的输出后会显示错误(没有此类文件或目录)。
似乎命令 /opt/hyperic/agent-current/bin/hq-agent.sh 没有在远程主机上执行。目的是执行命令 'cd /opt;ls 并将命令输出捕获到 host.txt 中提到的每个远程系统上的状态。
当我在远程系统上手动运行命令时,会返回以下输出。关于这里可能出现什么问题的任何帮助?
~]# /opt/hyperic/agent-current/bin/hq-agent.sh status | awk 'NR==1{print $3 $4}'
正在运行
脚本如下
#!/bin/bash
while read host; do
if ssh -o StrictHostKeyChecking=no -n root@$host '[ "$(awk "/CentOS/{print}" /etc/*release)" ] '
then
echo "(centos)"
ssh -o StrictHostKeyChecking=no -n root@$host 'cd /opt;ls'
STATUS=`/opt/hyperic/agent-current/bin/hq-agent.sh status | awk 'NR==1{print $3 $4}'`
if [ "$STATUS" == "isrunning" ]
then
echo "$HOST == PASS"
else
echo "$HOST == FAIL"
fi
else
echo "(generic)"
fi
done < hosts.txt
脚本的输出 --
root@10.10.1.1's password:
firstboot
puppet
./hq-enhanced.sh: line 14: /opt/hyperic/agent-current/bin/hq-agent.sh: No such file or directory
== FAIL
【问题讨论】: