I'm writting a bash script to change all fortigate's passwords. I have to pick all IP public fortigates and I have to test if the connection is good or bad. With the command below I know that my ssh connection return some errors, 0=connection is good.
sshpass -p [PASSWORD] ssh -q -oStrictHostKeyChecking=no [USERNAME]@[LOCAL_IP] > /dev/null
Now I want to put this in my script to test all fortigates ssh connections and to put this in a mail. But when I put the command in my while loop, the loop is running only one time ( totaly work without testing ssh connection)
if [ "$?" == "0" ]
then
echo "(./forti.sh) | sshpass -p $p ssh -oStrictHostKeyChecking=no $u@$IP" >> $base/change_password.sh
./change_password.sh
echo "<td id="rouge"></td>" >> pass_mail.html
rm $base/change_password.sh
else
echo "<td id="rouge"></td>" >> pass_mail.html
rm $base/change_password.sh
fi
So this is my script block who verify the condition in case the fortigate is up, as I said before the while loop is running one time even if it's true.
Have you got any idea of my issue ?
Do not hesitate to ask details if it's not clear enough.
Thanks.