#!/bin/sh
#
case $* in
 -d) PARAM=`/bin/date +%d.%m.%Y`;;
 -m) PARAM=`/bin/date +%m.%Y`;; -y)
 PARAM=`/bin/date +%Y`;;
 -?|-h|--help) echo "calc [-d|-m|-y|<pattern>]"
 echo "Berechnet online-Zeit, Zugriffe"
echo
 exit;;
 *) PARAM="$*";;
esac
grep "$PARAM" /etc/ppp/online-time |
 awk 'BEGIN { total=0 }
NF == 5 {
 n=split($1,d,".")
 date1=(d[1]+d[2]*30+d[3]*365)
 n=split($2,t,":")
 time1=(t[1]*3600+t[2]*60+t[3])
 n=split($4,d,".")
date2=(d[1]+d[2]*30+d[3]*365)
 n=split($5,t,":")
 time2=(t[1]*3600+t[2]*60+t[3])
 time=(date2-date1)*3600*24+time2-time1
 total=total+time
}
END \
{
 hours = total / 3600
 print NR" connects, "hours" hours, (= "total" seconds)"
}'
