Browse Source

init

master
gsd 6 months ago
parent
commit
4d969e7e96
  1. 69
      pingtest.sh

69
pingtest.sh

@ -24,6 +24,7 @@
# yandex dns & google
ALLDEST="77.88.8.8 8.8.8.8"
#ALLDEST="172.16.0.1"
# Interface to reset, usually your WAN
BOUNCE=pppoe0
# Log file
@ -32,50 +33,40 @@ LOGFILE=/root/pingtest.log
#init ping count
COUNT=1
#max pings
RUNSOFT_PING=60
IWANNADIE_PING=110
MAXPING=120
RUNSOFT_PING=30
IWANNADIE_PING=60
MAXPING=70
function shutdownThis {
/sbin/shutdown -r now >> $LOGFILE
}
function trySoftReUp {
/sbin/ifconfig $BOUNCE down
# Give interface time to reset before bringing back up
sleep 10
/sbin/ifconfig $BOUNCE up
# Give WAN time to establish connection
sleep 60
}
while [ $COUNT -le $MAXPING ]
do
for DEST in $ALLDEST
do
#echo `date +%Y%m%d.%H%M%S` "Pinging $DEST" >> $LOGFILE
ping -c 1 -W 1 $DEST >/dev/null 2>/dev/null
if [ $? -eq 0 ]
then
#echo `date +%Y%m%d.%H%M%S` "Ping $DEST OK." >> $LOGFILE
exit 0
fi
done
for DEST in $ALLDEST
do
#echo `date +%Y%m%d.%H%M%S` "Pinging $DEST" >> $LOGFILE
ping -c1 $DEST >/dev/null 2>/dev/null
if [ $? -eq 0 ]
then
#echo `date +%Y%m%d.%H%M%S` "Ping $DEST OK." >> $LOGFILE
exit 0
fi
done
if [ $COUNT -eq $RUNSOFT_PING ]
then
echo `date +%Y%m%d.%H%M%S` "All pings failed. Resetting interface $BOUNCE." >> $LOGFILE
#trySoftReUp
fi
echo "$COUNT try to ping"
if [ $COUNT -eq $RUNSOFT_PING ]
then
echo `date +%Y%m%d.%H%M%S` "All pings failed. Resetting interface $BOUNCE." >> $LOGFILE
/sbin/ifconfig $BOUNCE down
sleep 10
/sbin/ifconfig $BOUNCE up
sleep 60
fi
if [ $COUNT -eq $IWANNADIE_PING ]
then
echo `date +%Y%m%d.%H%M%S` "All pings failed twice. Rebooting..." >> $LOGFILE
#shutdownThis
exit 1
fi
if [ $COUNT -eq $IWANNADIE_PING ]
then
echo `date +%Y%m%d.%H%M%S` "All pings failed twice. Rebooting..." >> $LOGFILE
/sbin/shutdown -r now >> $LOGFILE
exit 1
fi
COUNT=`expr $COUNT + 1`
COUNT=`expr $COUNT + 1`
done

Loading…
Cancel
Save