Ping不出去斷網主機就自動關機

#!/bin/bash
count=0
while true; do
ping -c 1 8.8.8.4
r=$?
echo "`date` result $r (0:success, 1:loss 100% 2:unreachable)" >> log.txt
if [[ $r != 0 ]]; then
((count++))
echo "loss $count"
else
echo "count reset to 0"
count=0
fi
if [[ $count>=5 ]]; then
echo "`date` start to shutdown now , hehehe" >> log.txt
shutdown -h now
else
sleep 120
fi
done