I don't script everyday (I would like to)...so these skills are perishable.
I have a script that will ping servers, show that they are up. This is my code that works, which is a for loop.
Code:
#!/bin/bash
for hostname in server{1..4}
do
ping -c 1 -t 1 $hostname > /dev/null && echo "${hostname} appears up";
done
Output of code below:
Code:
server1 appears up
server2 appears up
server3 appears up
server4 appears up
I want to add a while loop to encompass the for loop, as I want it to continually ping all servers until the servers are up, and once all ping back successfully, then drop out of the loop and and the script.
Code:
#!/bin/bash
UNREACHABLE=1;
while [ $UNREACHABLE -ne "0" ];
do
ping -c 1 -t 1 $hostname > /dev/null && echo "{hostname} appears up";
done
When I run this, I'm getting "syntax error." I'm just not clicking with how to combine the two.
thanks