summaryrefslogtreecommitdiff
path: root/scripts/pppoe-status (plain)
blob: 9fe89cdd9ccc714db0e5ed7e403d0e123fa62ef9
1#!/bin/sh
2#***********************************************************************
3#
4# pppoe-status
5#
6# Shell script to report on status of PPPoE connection
7#
8# Copyright (C) 2000-2001 Roaring Penguin Software Inc.
9#
10# $Id$
11#
12# This file may be distributed under the terms of the GNU General
13# Public License.
14#
15# LIC: GPL
16#
17# Usage: pppoe-status [config_file]
18# If config_file is omitted, defaults to /etc/ppp/pppoe.conf
19#
20#***********************************************************************
21
22# Defaults
23CONFIG=/etc/ppp/pppoe.conf
24
25case "$#" in
26 1)
27 CONFIG="$1"
28 ;;
29esac
30
31if [ ! -f "$CONFIG" -o ! -r "$CONFIG" ] ; then
32 echo "$0: Cannot read configuration file '$CONFIG'" >& 2
33 exit 1
34fi
35
36. $CONFIG
37
38PPPOE_PIDFILE="$PIDFILE.pppoe"
39PPPD_PIDFILE="$PIDFILE.pppd"
40
41if [ "$DEMAND" != "no" ] ; then
42 echo "Note: You have enabled demand-connection; pppoe-status may be inaccurate."
43fi
44
45# If no PPPOE_PIDFILE, connection is down, unless we're using the Linux plugin
46if [ "$LINUX_PLUGIN" = "" ] ; then
47 if [ ! -r "$PPPOE_PIDFILE" ] ; then
48 echo "pppoe-status: Link is down (can't read pppoe PID file $PPPOE_PIDFILE)"
49 exit 1
50 fi
51fi
52
53# If no PPPD_PIDFILE, something fishy!
54if [ ! -r "$PPPD_PIDFILE" ] ; then
55 echo "pppoe-status: Link is down (can't read pppd PID file $PPPD_PIDFILE)"
56 exit 1
57fi
58
59PPPD_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.
64for 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 "pppoe-status: Link is attached to $IF, but $IF is down"
73 exit 1
74 fi
75 echo "pppoe-status: Link is up and running on interface $IF"
76 /sbin/ifconfig $IF
77 exit 0
78 fi
79 fi
80done
81
82echo "pppoe-status: Link is down -- could not find interface corresponding to"
83echo "pppd pid $PPPD_PID"
84exit 1