Initial import
This commit is contained in:
52
reconnect_inet.sh
Executable file
52
reconnect_inet.sh
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
device=$1
|
||||
device=${device:="ppp0"}
|
||||
|
||||
provider=$2
|
||||
provider=${provider:="dsl-provider"}
|
||||
|
||||
reconnect() {
|
||||
## - shutdown dsl line
|
||||
## -
|
||||
ifdown $provider >/dev/null 2> /dev/null
|
||||
sleep 2
|
||||
|
||||
## - If shutdown wasn't successful, kill the concerning pid
|
||||
## -
|
||||
PID=`ps ax | grep pppd | grep -v grep | grep $provider | awk '{print$1}'`
|
||||
while [ -n "$PID" ]; do
|
||||
kill -9 $PID
|
||||
sleep 2
|
||||
PID=`ps ax | grep pppd | grep -v grep | grep $provider | awk '{print$1}'`
|
||||
done
|
||||
|
||||
## - Bring up dsl line
|
||||
## -
|
||||
_date=`date +"%d.%m.%Y %H:%M:%S"`
|
||||
ifup $provider >/dev/null 2> /dev/null
|
||||
sleep 2
|
||||
|
||||
|
||||
#echo -n "`hostname --long` reconnected at `date +\"%d.%m.%Y %H:%M:%S\"`"
|
||||
|
||||
declare -i _number=0
|
||||
ptp_addr=`ifconfig $device 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f3 | cut -d " " -f1`
|
||||
while [ -z "$ptp_addr" ]; do
|
||||
[[ $_number -eq 90 ]] && break
|
||||
sleep 1
|
||||
ptp_addr=`ifconfig $device 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f3 | cut -d " " -f1`
|
||||
let _number++
|
||||
done
|
||||
|
||||
if [ "X$ptp_addr" = "X" ] ; then
|
||||
echo ""
|
||||
echo "[ ERROR ]: reconnection host `hostname --long` failed at `date +\"%d.%m.%Y %H:%M:%S\"`"
|
||||
fi
|
||||
}
|
||||
|
||||
reconnect
|
||||
|
||||
exit 0;
|
||||
Reference in New Issue
Block a user