#!/bin/sh
#
# calc: summarizes the online time of your isdn-connects in the
# following format:
# 105 connects 10 hours 20 minutes 5.00 seconds
#
# Options: -d prints out the data for today
# -m prints out the data for this month
# -y prints out the data for this year
# prints out the data included "pattern"
#
# Examples: - onlinecalc 01.2001
# prints out the data for January 2001
# - onlinecalc -m
# prints out the data for the actual month
#
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" /var/log/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
N = N + 1
}
END {
hours = (total / 3600) - ((total / 3600) % 1)
minutes = ((total / 3600) % 1) * 60
seconds = (minutes % 1) * 60
printf "%d %-8s %d %-5s %d %-7s %.2f %-7s\n",N,"connects",hours,"hours",minutes,"minutes",seconds,"seconds"
}'