home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 March / PCWELT_3_2006.ISO / base / 05_common.mo / usr / sbin / adsl-status < prev    next >
Encoding:
Text File  |  2003-03-02  |  2.1 KB  |  84 lines

  1. #!/bin/sh
  2. #***********************************************************************
  3. #
  4. # adsl-status
  5. #
  6. # Shell script to report on status of ADSL connection
  7. #
  8. # Copyright (C) 2000-2001 Roaring Penguin Software Inc.
  9. #
  10. # $Id: adsl-status,v 1.3 2002/04/09 17:28:39 dfs Exp $
  11. #
  12. # This file may be distributed under the terms of the GNU General
  13. # Public License.
  14. #
  15. # LIC: GPL
  16. #
  17. # Usage: adsl-status [config_file]
  18. # If config_file is omitted, defaults to /etc/ppp/pppoe.conf
  19. #
  20. #***********************************************************************
  21.  
  22. # Defaults
  23. CONFIG=/etc/ppp/pppoe.conf
  24.  
  25. case "$#" in
  26.     1)
  27.     CONFIG="$1"
  28.     ;;
  29. esac
  30.  
  31. if [ ! -f "$CONFIG" -o ! -r "$CONFIG" ] ; then
  32.     echo "$0: Cannot read configuration file '$CONFIG'" >& 2
  33.     exit 1
  34. fi
  35.  
  36. . $CONFIG
  37.  
  38. PPPOE_PIDFILE="$PIDFILE.pppoe"
  39. PPPD_PIDFILE="$PIDFILE.pppd"
  40.  
  41. if [ "$DEMAND" != "no" ] ; then
  42.     echo "Note: You have enabled demand-connection; adsl-status may be inaccurate."
  43. fi
  44.  
  45. # If no PPPOE_PIDFILE, connection is down, unless we're using the Linux plugin
  46. if [ "$LINUX_PLUGIN" = "" ] ; then
  47.     if [ ! -r "$PPPOE_PIDFILE" ] ; then
  48.     echo "adsl-status: Link is down (can't read pppoe PID file $PPPOE_PIDFILE)"
  49.     exit 1
  50.     fi
  51. fi
  52.  
  53. # If no PPPD_PIDFILE, something fishy!
  54. if [ ! -r "$PPPD_PIDFILE" ] ; then
  55.     echo "adsl-status: Link is down (can't read pppd PID file $PPPD_PIDFILE)"
  56.     exit 1
  57. fi
  58.  
  59. PPPD_PID=`cat "$PPPD_PIDFILE"`
  60.  
  61. # Sigh.  Some versions of pppd put PID files in /var/run; others put them
  62. # in /etc/ppp.  Since it's too messy to figure out what pppd does, we
  63. # try both locations.
  64. for i in /etc/ppp/ppp*.pid /var/run/ppp*.pid ; do
  65.     if [ -r $i ] ; then
  66.     PID=`cat $i`
  67.     if [ "$PID" = "$PPPD_PID" ] ; then
  68.         IF=`basename $i .pid`
  69.         netstat -rn | grep " ${IF}\$" > /dev/null
  70.         # /sbin/ifconfig $IF | grep "UP.*POINTOPOINT" > /dev/null
  71.         if [ "$?" != "0" ] ; then
  72.         echo "adsl-status: Link is attached to $IF, but $IF is down"
  73.         exit 1
  74.         fi
  75.         echo "adsl-status: Link is up and running on interface $IF"
  76.         /sbin/ifconfig $IF
  77.         exit 0
  78.     fi
  79.     fi
  80. done
  81.  
  82. echo "adsl-status: Link is down -- could not find interface corresponding to"
  83. echo "pppd pid $PPPD_PID"
  84. exit 1