#!/usr/local/bin/bash

# Made by: M.Mastenbroek 2003
# For more info see http://machiel.generaal.net


ppp_process_pid=`ps -aux | grep ppp | grep -v grep | grep -v ppp_| awk '{ print $2 }'`
ppp_process=`echo "$ppp_process_pid" | wc -w | tr -d ' '`
inet_ip_address=`ifconfig | grep -A 3 "tun0:" | grep -c inet`
ppp_log=`cat /var/log/ppp.log | tail -1  | awk '{print $NF }'`

if [ $ppp_process == 0 ]
then
  echo "no connection"
else
  if [ $inet_ip_address != 2 ]
  then
    if [ $ppp_log == "CONNECT" ]
    then
      echo "dialing"
    else
      if [ $ppp_log == "Closing" ]
      then
        echo "closing connection"
      else
        if [ $ppp_log == "Dead" ]
        then
          echo "phone dead"
          kill $ppp_process_pid
        else
          echo "unknown status"
        fi
      fi
    fi
  else
    if [ $ppp_log == "Closing" ]
    then
      echo "closing connection"
    else
      echo "internet connection"
    fi
  fi
fi

exit 0

