Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force DSL line reconnection #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions misc/scripts/usr/local/sbin/provider-reconnect
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# force ip change on dialup lines
# AGPL (Markus neubauer( et) std - service.com) 2015

# Description:
# some DSL providers disconnect after 24h of online time, to have control
# over that behaviour, you can do it yourself in a nightly period where
# nobody will be diconnected.

# You need to:
## put a unhashed stanca in your crontab or make it otherwise a nightly task
## example:
#11 04 * * * /usr/local/sbin/provider-reconnect

## variables - adapt to your needs
HOSTMASTER="[email protected]" # your hostmaster address
subject="Neue externe IP Adresse" # mail subject
EXTERNAL_IF="eth0" # your external interface
USE_DDCLIENT="on" # set to no if youre not using ddclient

## force reconnect function
function reconnect_provider {
ifdown ${EXTERNAL_IF}
sleep 1
ifup ${EXTERNAL_IF}
}

## mainline code
workfile=`mktemp`

while read msg; do

if [[ "$msg" =~ "DHCPRELEASE" ]] ; then
GW=`echo $msg | cut -d' ' -f5`
echo "OLD GATEWAY: $GW" >> $workfile

elif [[ "$msg" =~ "DHCPACK" ]] ||
GW=`echo $msg | cut -d' ' -f3`
echo "NEW EXTERNAL GATEWAY: $GW" >> $workfile

elif [[ "$msg" =~ "bound to" ]]; then
subject="$subject `echo $msg | cut -d' ' -f3`"
if [ 'on' == "$USE_DDCLIENT" ]; then
service ddclient force-reload > /dev/null
fi
fi
done <<< "`reconnect_provider 2>&1`"

mail -s "$subject" ${HOSTMASTER} < $workfile

rm $workfile

## eof