shell | scripting ping

Theres a little problem using ping as a connection checker inside of scripts. In example: If you send a bulk of three pings and one of them fail, the ping coommand returns 1.
Here is a workaround:

function ping_wrapper() {
while true; do
ping -q -c 1 -w $C_TIMEOUT $C_IP > /dev/null && break
CNT=$(($CNT + 1))
if [ $CNT -eq $C_CNT ]; then return 1; fi
return 0

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.