#!/bin/sh

RUN_DIR=/var/run
AWK=/bin/awk
GREP=/bin/grep
ROUTE=/sbin/route
KILL=/bin/kill

IP=`echo $3 | grep -P '^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'`
if [ "$3" = "$IP" ]; then
	PPP_ID=`$ROUTE -n | $GREP $IP | $AWK {'print $8'}`
	if [ "x$PPP_ID" = "x" ]; then
		echo "Can't find ppp process with $IP ip address" >&2
		exit 1
	fi
	PID_FILE="$RUN_DIR/$PPP_ID.pid"

	PPP_PID=`sed 's/ //g' $PID_FILE`

	$KILL $PPP_PID
	sleep 5
	$KILL -TERM $PPP_PID

	rm -f $PID_FILE > /dev/null
else
	echo "Wrong IP"
fi

