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

1b9e20
#!/bin/bash
1b9e20
#
1b9e20
# pppd_getProcessIds.sh --- This function parses the pppd's log
1b9e20
# messages and returns the process ids of each pppd connection.
1b9e20
#
1b9e20
# This function works with regular pppd log messages like the following:
1b9e20
#
1b9e20
#    Jul 13 00:04:42 projects pppd[8076]: pppd 2.4.4 started by root, uid 0
1b9e20
#    Jul 13 00:04:42 projects pppd[8076]: Using interface ppp0
1b9e20
#    Jul 13 00:04:42 projects pppd[8076]: local  IP address 10.64.64.64
1b9e20
#    Jul 13 00:04:42 projects pppd[8076]: remote IP address 10.112.112.112
1b9e20
#    Jul 13 00:04:58 projects pppd[8076]: Starting link
1b9e20
#    Jul 13 00:05:34 projects pppd[8076]: Serial connection established.
1b9e20
#    Jul 13 00:05:34 projects pppd[8076]: Connect: ppp0 <--> /dev/ttyACM0
1b9e20
#    Jul 13 00:05:36 projects pppd[8076]: PAP authentication succeeded
1b9e20
#    Jul 13 00:05:36 projects pppd[8076]: Local IP address changed to 200.55.159.1
1b9e20
#    Jul 13 00:05:36 projects pppd[8076]: Remote IP address changed to 192.168.254.182
1b9e20
#    Jul 13 01:53:30 projects pppd[8076]: Terminating on signal 15
1b9e20
#    Jul 13 01:53:30 projects pppd[8076]: Connect time 107.9 minutes.
1b9e20
#    Jul 13 01:53:30 projects pppd[8076]: Sent 2243056 bytes, received 21047698 bytes.
1b9e20
#    Jul 13 01:53:36 projects pppd[8076]: Connection terminated.
1b9e20
#    Jul 13 01:53:37 projects pppd[8076]: Terminating on signal 15
1b9e20
#    Jul 13 01:53:37 projects pppd[8076]: Exit.
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_getProcessIds {
1b9e20
1b9e20
    echo "$MESSAGES" | gawk '{print $5}' \
1b9e20
        | sed -r 's!pppd\[([0-9]+)]:!\1!' | sort | uniq
1b9e20
1b9e20
}