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() {
C_IP="$1"
C_CNT="$2"
C_TIMEOUT="$3"
CNT=0
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
done
return 0
}