#!/bin/sh # # v1, ADSL connection monitor # # 2001, Alex # # Edit below values to your own preferences # IP of remote end of pptp tunnel REMOTE_IP='195.190.241.152' # Set the ADSL reconnect monitor log file (tm) LOGFILE=/var/log/adsl # Verbosity level, 0 = silent, 1 = noisy VERBOSE=0 # Do not edit anything below, do not even look. # Grab them pid's PPTP_MNG_PID=`ps x|grep 'call manager'|grep -v grep| awk '{print $1}'` PPTP_GRE_PID=`ps x|grep 'PPP gateway'|grep -v grep| awk '{print $1}'` PPPD_PID=`ps x|grep 'pppd'|grep -v grep| awk '{print $1}'` # Ping our remote end of the pptp tunnel if ping -w 1 -c 1 $REMOTE_IP > /dev/null 2>&1; then if [ $VERBOSE = 1 ]; then # Print nice message, duh (-: echo "ADSL connection is just fine" fi # Write to log file echo -n `date | awk '{print $2,$3,$4}'` >> $LOGFILE echo " ADSL connection is just fine" >> $LOGFILE # Terminate cleanly exit fi # We're officially offline now # Go do something about it # Finish that call manager if [ ! -z $PPTP_MNG_PID ]; then kill -9 $PPTP_MNG_PID fi # Demolish those GRE-to-PPP gateway troubles if [ ! -z $PPTP_GRE_PID ]; then kill -9 $PPTP_GRE_PID fi # Kill off PPP daemon if [ ! -z $PPPD_PID ]; then kill -9 $PPPD_PID fi # Just make sure there are no files lingering rm -rf /var/run/pptp.pid > /dev/null 2>&1 rm -rf /var/run/pptp > /dev/null 2>&1 # Delete them interfaces ifconfig ppp0 delete > /dev/null 2>&1 ifconfig ppp1 delete > /dev/null 2>&1 # Sleep for safety sleep 1 # Reconnect to ADSL stuff pptp 10.0.0.138 > /dev/null 2>&1 wait # Write to screen echo "ADSL connection probably up now.." # Write to log file echo -n `date | awk '{print $2,$3,$4}'` >> $LOGFILE echo " ADSL connection probably up now.." >> $LOGFILE