#!/bin/sh
######################################################################
#
# Determine the device to be terminated.
# Author: gavin.kx@qq.com
# Date: 02-7,2012
# Support Emailgavin.kx@qq.com  QQ935790243
#if [ "$1" = "" ]; then
#	echo "ERROR: Parameter error"
#	echo "Usage: $0 <device_filename>"
#	echo "eg: $0 /dev/ttyUSB2"
#	exit 1
#else
	DEVICE=/dev/ttyUSB2
#fi
######################################################################
#
#PID=`ps -ef | grep -v grep | grep "$DEVICE" | grep "pppd" | awk '{ print $2; exit }'`
echo "begin ppp off"
PID=`ps  -A | grep pppd | awk '{ print $1; exit }'`
echo "ppp pid: $PID"
if test $PID; then
        kill $PID

        if [ ! "$?" = "0" ]; then
                echo "ERROR: Terminated ppp link to $DEVICE failed"
               # exit 3
        fi
#
# Success. wait 3 seconds to let pppd clean up its own junk.
        echo "PPP link to $DEVICE terminated"
        #exit 0
else
sleep 2
echo "ERROR: PPP link is not active on $DEVICE"
#
fi
#exit 2
