#!/bin/bash
#
# pppd_getEntries.sh -- This script returns entries generated by a
# succesful (on demand) pppd interaction for specific interfaces.
#
# Copyright (C) 2012 Alain Reguera Delgado
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# ----------------------------------------------------------------------
# $Id$
# ----------------------------------------------------------------------
function pppd_getEntries {
local PROCESS_ID=''
local PROCESS_IDS=''
local ENTRY=''
# Build list of pppd's process ids.
PROCESS_IDS=$(pppd_getProcessIds)
# Build list of entries related to pppd established connections.
for PROCESS_ID in $PROCESS_IDS;do
# Increment entry counter to know where we are.
(( ENTRIES_CNT++ ))
# Define an entry.
ENTRY=$(echo "$MESSAGES" \
| gawk '{if ($5 ~ /pppd\['${PROCESS_ID}']:/) print $0}' )
# Exclude entries related to interfaces different from that
# one already specified.
echo "$ENTRY" | egrep "Using interface ${INTERFACE_REGEX}" > /dev/null
if [[ $? -eq 1 ]];then
continue
fi
# Add entry to list of entries.
ENTRIES=$(echo "${ENTRY}"; echo "${ENTRIES}")
done
# Sort list of entries.
ENTRIES=$(echo "$ENTRIES" | sort )
}