I wrote a script that shut down all servers in our environment. But if some server is not reachable to begin with or if it is already down, my script just hangs and nothing happens. How may I make it move ahead if some server is unreachable?
#!/bin/bash #script for Shutting down all VM & BM. Region=$1 user=$2 region_file_path="/region/$Region.txt" host=`cat $region_file_path` key_path="/root/.ssh/id_rsa_adminpod" for i in $host do # echo "Shutting down Host in $Region with ip addrss $i" ssh -i $key_path -p 2222 $user@$i "sudo init 0" &> /dev/null if [ $? -ne 0 ]; then echo "$i is shutdown!" else echo "There is some issue, try again" exit 1 fi done