diff --git a/check_inet.sh b/check_inet.sh index 4e255c6..a87ab03 100755 --- a/check_inet.sh +++ b/check_inet.sh @@ -6,7 +6,7 @@ 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` +ptp_addr="$(ip addr show $device | grep peer | awk '{print$4}' | cut -d '/' -f1)" alternate_addr="google.com heise.de debian.org ubuntu.com" @@ -16,9 +16,9 @@ reconnect() { 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 + sleep 5 + ptp_addr="$(ip addr show $device | grep peer | awk '{print$4}' | cut -d '/' -f1)" + if [[ -z "$ptp_addr" ]] ; 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\"`" @@ -27,7 +27,7 @@ reconnect() { echo "`df`" } -if [ "X$ptp_addr" == "X" ] ; then +if [[ -z "$ptp_addr" ]] ; then reconnect else ping -c3 $ptp_addr >/dev/null 2> /dev/null