Add check_inet script.
This commit is contained in:
parent
8c8f482066
commit
0fdb97ae7c
46
check_inet.sh
Executable file
46
check_inet.sh
Executable file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
device=${1:-"ppp0"}
|
||||
|
||||
provider=${2:-"dsl-provider"}
|
||||
|
||||
ptp_addr=`ifconfig $device 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f3 | cut -d " " -f1`
|
||||
|
||||
alternate_addr="google.com heise.de debian.org ubuntu.com"
|
||||
|
||||
reconnect() {
|
||||
ifdown $provider >/dev/null 2> /dev/null
|
||||
sleep 5
|
||||
killall -9 pppd
|
||||
sleep 2
|
||||
ifup $provider >/dev/null 2> /dev/null
|
||||
sleep 3
|
||||
ptp_addr=`ifconfig $device 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f3 | cut -d " " -f1`
|
||||
if [ "X$ptp_addr" == "X" ] ; then
|
||||
echo "[ Error ]: reconnection host `hostname --long` failed at `date +\"%d.%m.%Y %H:%M:%S\"`"
|
||||
else
|
||||
echo "[ `hostname --long`]: reconnected at `date +\"%d.%m.%Y %H:%M:%S\"`"
|
||||
fi
|
||||
echo ""
|
||||
echo "`df`"
|
||||
}
|
||||
|
||||
if [ "X$ptp_addr" == "X" ] ; then
|
||||
reconnect
|
||||
else
|
||||
ping -c3 $ptp_addr >/dev/null 2> /dev/null
|
||||
rval=$?
|
||||
if [ $rval -ne 0 ]; then
|
||||
for ip_addr in $alternate_addr ; do
|
||||
ping -c3 $ip_addr >/dev/null 2> /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
exit 0
|
||||
fi
|
||||
done;
|
||||
reconnect
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0;
|
Loading…
Reference in New Issue
Block a user