I have list for servers say server1, server2, server3.....server20
I want to test the ssh connectivity of each server, if any one of the server is down then ssh connectivity fails and the script results something like echo "serever is not reachable"
Now I m confused using which command shall I check if the server is not reachable using ssh,
can any one suggest the best solution for this so that I can add it in my code
below are the two command I found and how it works:
command1:
success case:
ssh -q user@$server1 exit
bash-3.00$ echo $?
0
failure case:
ssh -q user@$server1000 exit
bash-3.00$ echo $?
255
command2:
success case:
ssh -o ConnectTimeout=3 user@$server1 exit
bash-3.00$ echo $?
0
failure case:
ssh -o ConnectTimeout=3 user@$server1000 exit
ssh: server1000: node name or service name not known
bash-3.00$ echo $?
255