I'd suggest to try:
#!/bin/bash
#
ok="`ping -c 2 google.com 2>&1`"
res="$?"
if [ "$res" != "0" ] ; then
sleep 10
ok2="`ping -c 2 google.com 2>&1`"
res2="$?"
if [ "$res2" != "0" ] ; then
echo "Failed twice ... res=$res res2=$res2 ..."
echo -e "Ping1:\n$ok"
echo -e "Ping2:\n$ok2"
.... your preferred restart ...
fi
fi
Holly code, that's working better now! Tottemo arigatou Kano-san.