networking - Checking host availability by using ping in bash scripts -


i want write script, keep checking if of devices in network, should online day long, online. tried use ping, but

if [ "`ping -c 1 some_ip_here`" ]   echo 1 else   echo 0 fi 

gives 1 no matter if enter valid or invalid ip address. how can check if specific address (or better of devices list of ip addresses) went offline?

ping returns different exit codes depending on type of error.

ping 256.256.256.256 ; echo $? # 68  ping -c 1 127.0.0.1 ; echo $? # 0  ping -c 1 192.168.1.5 ; echo $? # 2 

0 means host reachable

2 means unreachable


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -