I have multiple servers and want to set up a periodic check so that trapserver(s) has correct trapaddress(es). trapserver 1 as 10.10.10.1 and trapserver2 as 10.10.10.2. However the below script does not see $trapaddress value of 10.10.10.x with "10.10.10.x" as equal?
Not sure where I am going wrong?
Many thanks
#!/bin/bash
for LINE in $( cat /home/username/serverslist.txt )
do
SERVER=`(echo $LINE | awk -F : '{ print $1 }')`
echo " "
echo $SERVER
traphost=$( ssh $SERVER -t sudo cat /etc/traphost.txt )
trapaddress=$( ssh $SERVER -t sudo cat /etc/trapaddress.txt )
echo -e " Traphost is $traphost \n Trapaddress is $trapaddress"
if [ $traphost = "trapserver1" ] && [ $trapaddress= "10.10.10.1" ] || [ $traphost = "trapserver2" ] && [ $trapaddress= "10.10.10.2" ] ;
then
echo "server is happy."
else
echo " $servername server has incorrect $trapaddress ."
fi
done
=
in the tests. In other words, replace[ $trapaddress= "10.10.10.1" ]
with[ "$trapaddress" = "10.10.10.1" ]
– John1024 Feb 19 '19 at 21:50