This script reads the system IP from hosts.txt, login to system, checks the OS type, executes a set of commands and print the output.
The ssh portion works fine, however the error (No such File or Directory) is shown after displaying output for 'ls''.
It seems the command /opt/hyperic/agent-current/bin/hq-agent.sh is not getting executed on remote host. The intend is to execute commands 'cd /opt;ls and also capture the command output to STATUS on each remote systems mentioned in host.txt.
When I run manaully the command on the remote system, the below output is returned. Any help on what could be wrong here?
~]# /opt/hyperic/agent-current/bin/hq-agent.sh status | awk 'NR==1{print $3 $4}'
isrunning
script is as below
#!/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
Output of the script --
[email protected]'s password:
firstboot
puppet
./hq-enhanced.sh: line 14: /opt/hyperic/agent-current/bin/hq-agent.sh: No such file or directory
== FAIL