#!/bin/bash
#############################################
#											#
#	quick & dirty pppd logfile parser		#
#	2008, Thomas Redmer						#
#	thomas@redmer.net						#
#											#
#############################################

#############################################
#	variables fitting for OS X Leopard
#	change if needed
#############################################

LOGFILE="/var/log/ppp.log"
LOGFILES_BZ="/var/log/ppp.log.*.bz2"
TEMP_FILE="${TMPDIR}ppp.log.tmp"




#############################################
#	actual script starts below
#	no need to edit if you don't know what you're doing
#############################################

bzcat `ls -tr $LOGFILES_BZ` | grep "bytes" > $TEMP_FILE
cat $LOGFILE | grep "bytes" >> $TEMP_FILE

for MONTH in Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
do
	grep "$MONTH" $TEMP_FILE | \
	awk -v month=$MONTH '
		BEGIN {
			printf("=====================================================================\n");
			printf("%24s        MB sent    MB received       MB total\n", month);
		}
		{
			printf("%s %s %2.0f %s %s %14.1f %14.1f %14.1f\n", $1, $2, $3, $4, $5, $8/1024/1024, $11/1024/1024, ($8+$11)/1024/1024);
			sent+=$8;
			received+=$11;
			total+=$8+$11
		}
		END {
			printf("%18s total %14.1f %14.1f %14.1f\n", month, sent/1024/1024, received/1024/1024, total/1024/1024);
		}
	'
done