Categories
Programming

Test if pingable

The code snippet belows try to ping $host. if ping fails (ping returns none zero value exitcode) the script exits.

[code language=”bash”]
#!/bin/bash
if [ $ping -eq "1" ] ; then
if ! ping -w 4 -c 1 $host > /dev/null 2>&1 ; then
exit
fi;
fi;
[/code]