Blame Scripts/Bash/Functions/Report/Pppd/pppd_getEntries.sh

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