#!/bin/bash

# Copyright (c) 2000 by Network TeleSystems, Inc.
# All rights reserved.
# Internet http://www.nts.com
#
# Please direct all support-related calls to your licensed Internet Service 
# Provider.  NTS does not provide direct support.  NTS works through Internet
# Service Providers that have licensed our software.

unset LastRun
unset pids
unset pppd_pids
unset GrepExp
unset target

pids=`pidof pppoed`

if [ -z "$pids" ]; then
	echo
	echo "There are no active PPPoE sessions running."
	echo
	LastRun=`grep "pppoed\[" /var/log/messages|\
	grep ": Related PIDs"|tail -1`
	pids=${LastRun#*PIDs: }
	if [ -z "$pids" ]; then
		exit 1
	fi
	pids="$pids "
else
	pids="$pids "
	pppd_pids=`pidof pppd`
	if [ -n "$pppd_pids" ]; then
		pids="$pppd_pids"' '"$pids"
	fi
fi

while [ -n "$pids" ]; do
	target=${pids%% *}
	if [ -z "$GrepExp" ]; then
		GrepExp="\[$target\]"
	else
		GrepExp="\[$target\]\|$GrepExp"
	fi
	pids=${pids#* }
done

grep "$GrepExp" /var/log/messages
