You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.1 KiB

#!/bin/sh
#=====================================================================
# pingtest.sh, v1.0.1
# Created 2009 by Bennett Lee
# Released to public domain
#
# (1) Attempts to ping several hosts to test connectivity.  After
#    first successful ping, script exits.
# (2) If all pings fail, resets interface and retries all pings.
# (3) If all pings fail again after reset, then reboots pfSense.
#
# History
# 1.0.1  Added delay to ensure interface resets (thx ktims).
# 1.0.0  Initial release.
#=====================================================================
#=====================================================================
# USER SETTINGS
#
# Set multiple ping targets separated by space.  Include numeric IPs
# (e.g., remote office, ISP gateway, etc.) for DNS issues which
# reboot will not correct.
# 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
LOGFILE=/root/pingtest.log
#=====================================================================
#init ping count
COUNT=1
#max pings
RUNSOFT_PING=30
IWANNADIE_PING=60
MAXPING=70
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
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
/sbin/shutdown -r now >> $LOGFILE
exit 1
fi
COUNT=`expr $COUNT + 1`
done