#!/bin/bash
#
# Generate statistics in logfiles for ppp connections
#

# Loop for each pppd; Only static at the moment.
for EACHIF in ppp0 ppp1 ; do

  IFACE=${EACHIF}
  LOGFILE=/var/log/netstats.${IFACE}.log
  
  # If logfile doesn't exists, create it with header.
  if [ ! -w ${LOGFILE} ] ; then
    PPPLINE=" Date_Time      |"$(/usr/sbin/pppstats -av ${IFACE} |head -1)
    printf "${PPPLINE}\n" > ${LOGFILE}
  fi
  
  # Add line from pppstats to logfile
  PPPLINE=$(/bin/date +%Y%m%d_%H%M%S)" |"$(/usr/sbin/pppstats -av ${IFACE}|tail -1)
  printf "${PPPLINE}\n" >> ${LOGFILE}
  
done

