<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://cocnm.computerisms.ca/index.php?action=history&amp;feed=atom&amp;title=%2Froot%2Fscripts%2Fbwrprt.sh</id>
	<title>/root/scripts/bwrprt.sh - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://cocnm.computerisms.ca/index.php?action=history&amp;feed=atom&amp;title=%2Froot%2Fscripts%2Fbwrprt.sh"/>
	<link rel="alternate" type="text/html" href="http://cocnm.computerisms.ca/index.php?title=/root/scripts/bwrprt.sh&amp;action=history"/>
	<updated>2026-11-14T11:55:12Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>http://cocnm.computerisms.ca/index.php?title=/root/scripts/bwrprt.sh&amp;diff=386&amp;oldid=prev</id>
		<title>Bob at 03:49, 16 April 2014</title>
		<link rel="alternate" type="text/html" href="http://cocnm.computerisms.ca/index.php?title=/root/scripts/bwrprt.sh&amp;diff=386&amp;oldid=prev"/>
		<updated>2014-04-16T03:49:33Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;b&amp;gt;&amp;lt;center&amp;gt;BIG FAT NOTE: This script is know to have issues on fast connections, particularly when using 32 bit systems on connections that can exceed 4 GB/hour&amp;lt;br&amp;gt;&lt;br /&gt;
This script still works well enough for slower connections, but find a script for faster connections with a few more features here:  [[/root/scripts/bwrpt.pl]]&amp;lt;/center&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
## Written by Bob Miller&lt;br /&gt;
## Computerisms.ca&lt;br /&gt;
## Last updated October 2012&lt;br /&gt;
## Please feel free to share this script, but please do not claim it.&lt;br /&gt;
&lt;br /&gt;
## This script depends on xtables-addons, and usage of the ACCOUNT target.&lt;br /&gt;
&lt;br /&gt;
## This will set up the tables we need in iptables to do our accounting.  We need one entry for each lan subnet, and 0/0 is for the external address:&lt;br /&gt;
## iptables -t filter -I FORWARD -j ACCOUNT --addr 192.168.25.0/24 --tname lan&lt;br /&gt;
## iptables -t mangle -I POSTROUTING -j ACCOUNT --addr 0/0 --tname wan&lt;br /&gt;
&lt;br /&gt;
## Hostname detection currently requires at least the nbtscan program, make sure that and the iptaccount program are in your PATH&lt;br /&gt;
&lt;br /&gt;
## Set this program to run every hour in your crontab.  Note: if you can/will exceed the IPTWRAP or NETWRAP values in the space of one hour,&lt;br /&gt;
## you will need to run this script more often, and adjust the TTLNOW value and routine to account for minutes instead of just hours.&lt;br /&gt;
&lt;br /&gt;
#########################################################################################&lt;br /&gt;
#########################################################################################&lt;br /&gt;
##                                                                                     ##&lt;br /&gt;
##                          Configurable Options                                       ##&lt;br /&gt;
##                                                                                     ##&lt;br /&gt;
#########################################################################################&lt;br /&gt;
#########################################################################################&lt;br /&gt;
&lt;br /&gt;
## Next, we need to set up some variables to make configuration and life easy.&lt;br /&gt;
## Modify the following variables to your needs&lt;br /&gt;
&lt;br /&gt;
## Make sure your path includes the iptaccount and nbtscan commands&lt;br /&gt;
&lt;br /&gt;
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/scripts&lt;br /&gt;
&lt;br /&gt;
## Set a comma-separated list of recipients for the daily report&lt;br /&gt;
&lt;br /&gt;
ADMINML=bob.miller@computerisms.com&lt;br /&gt;
MLFRM=porchlian@computerisms.com&lt;br /&gt;
&lt;br /&gt;
## Set the total number of internal interfaces (do not include external interface) - Valid value is any integer higher than zero:&lt;br /&gt;
&lt;br /&gt;
NETNUM=2&lt;br /&gt;
&lt;br /&gt;
## these are the tables you configured your --tname as.  Add more NNM* variables as needed&lt;br /&gt;
&lt;br /&gt;
NNM1=computerisms&lt;br /&gt;
NNM2=pubaccess&lt;br /&gt;
NNM3=&lt;br /&gt;
NNM4=&lt;br /&gt;
&lt;br /&gt;
## For each table in iptaccount, Set the ethx interface of each port to match the NNM number (ie NNM1=IF1=ethx, NNM2=IF2=ethx)&lt;br /&gt;
&lt;br /&gt;
WAN=eth0&lt;br /&gt;
IF1=eth1&lt;br /&gt;
IF2=eth2&lt;br /&gt;
IF3=&lt;br /&gt;
IF4=&lt;br /&gt;
&lt;br /&gt;
## For the /sys statistics, the counter will wrap after a certain number of bits.  On a 32-bit system, the counter wraps at&lt;br /&gt;
## 32 bits (or (2^32)-1 or 4 GB, so set it as 4294967295.  on a 64-bit system, this number is (2^63)-1 or 18446744073709551615.  &lt;br /&gt;
## Set this number for NETWRAP.  For the iptaccount program, the wrap is currently hard coded to 32 bits so use 4294967295.  &lt;br /&gt;
## If this changes, it will presumably still need to wrap at some point, so set IPTWRAP to the number it wraps at.&lt;br /&gt;
## Set the wrap numbers:&lt;br /&gt;
&lt;br /&gt;
IPTWRAP=4294967295&lt;br /&gt;
NETWRAP=4294967295&lt;br /&gt;
&lt;br /&gt;
## Set a base directory to hold all your working stats.  Stat files will be kept here for archival purposes&lt;br /&gt;
&lt;br /&gt;
WRKDIR=/root/scripts/bwfiles&lt;br /&gt;
&lt;br /&gt;
## set how much data is your 100% monthly usage limit in GB (valid value is any integer greater than zero):&lt;br /&gt;
&lt;br /&gt;
USAGE=90&lt;br /&gt;
&lt;br /&gt;
## Set if you want Mega or Mebi (valid values are 1000 or 1024)&lt;br /&gt;
&lt;br /&gt;
DIV=1000&lt;br /&gt;
&lt;br /&gt;
## Totalling and reporting should happen only once per day, at the end of day.  &lt;br /&gt;
## This is a way of only running the totals on the last hour of production.  &lt;br /&gt;
## Set this value to the last hour of the day the script runs in 24-hour format&lt;br /&gt;
## Note that a report can only contain today&amp;#039;s data, so you can&amp;#039;t get 9-12PM on tomorrow&amp;#039;s report&lt;br /&gt;
## I put this here for testing, so I could make it run at the top of the next hour,&lt;br /&gt;
## But it might be useful if you shut your interface or machine down on a schedule.&lt;br /&gt;
&lt;br /&gt;
TTLNOW=23&lt;br /&gt;
&lt;br /&gt;
#########################################################################################&lt;br /&gt;
#########################################################################################&lt;br /&gt;
##                                                                                     ##&lt;br /&gt;
##                      END Configurable Options                                       ##&lt;br /&gt;
##                                                                                     ##&lt;br /&gt;
#########################################################################################&lt;br /&gt;
&lt;br /&gt;
## That should be all the configuration items required.  You probably shouldn&amp;#039;t modify the rest of this &lt;br /&gt;
## Here are more variables that we will need later.&lt;br /&gt;
&lt;br /&gt;
DOIPT=$(which iptaccount)&lt;br /&gt;
DONBT=$(which nbtscan)&lt;br /&gt;
&lt;br /&gt;
## The following variables need to be set to prevent unwanted effects:&lt;br /&gt;
&lt;br /&gt;
TTLIN=0&lt;br /&gt;
TTLOUT=0&lt;br /&gt;
TTLWAN=0&lt;br /&gt;
STIPTIN=0&lt;br /&gt;
STIPTOUT=0&lt;br /&gt;
TMTDIPTWAN=0&lt;br /&gt;
TMTDRAWWANIN=0&lt;br /&gt;
TMTDRAWWANOUT=0&lt;br /&gt;
TMTDRAWWAN=0&lt;br /&gt;
TMTDRAWWANIN=0&lt;br /&gt;
TMTDRAWWANOUT=0&lt;br /&gt;
TMTDIF=0&lt;br /&gt;
TMTDIFIN=0&lt;br /&gt;
TMTDIFOUT=0&lt;br /&gt;
TMTDLAN=0&lt;br /&gt;
TMTDLANIN=0&lt;br /&gt;
TMTDLANOUT=0&lt;br /&gt;
&lt;br /&gt;
## These variables will give us a way to deal with IP addresses.&lt;br /&gt;
&lt;br /&gt;
LAN1=$(/sbin/ifconfig $IF1 | sed -n -e&amp;#039;/inet addr:/s/^.*inet addr:\([0-9.]*\).*$/\1/p&amp;#039; | cut -f 1,2,3 -d .)&lt;br /&gt;
LAN2=$(/sbin/ifconfig $IF2 | sed -n -e&amp;#039;/inet addr:/s/^.*inet addr:\([0-9.]*\).*$/\1/p&amp;#039; | cut -f 1,2,3 -d .)&lt;br /&gt;
LAN3=$(/sbin/ifconfig $IF3 | sed -n -e&amp;#039;/inet addr:/s/^.*inet addr:\([0-9.]*\).*$/\1/p&amp;#039; | cut -f 1,2,3 -d .)&lt;br /&gt;
LAN4=$(/sbin/ifconfig $IF4 | sed -n -e&amp;#039;/inet addr:/s/^.*inet addr:\([0-9.]*\).*$/\1/p&amp;#039; | cut -f 1,2,3 -d .)&lt;br /&gt;
&lt;br /&gt;
## We need to create time variables for setting up our directory system and other things&lt;br /&gt;
&lt;br /&gt;
LOGDT=$(date &amp;quot;+%F %T&amp;quot;)&lt;br /&gt;
CURHOUR=$(date +%H)&lt;br /&gt;
YR=$(date +%Y)&lt;br /&gt;
MNTH=$(date +%m)&lt;br /&gt;
DAY=$(date +%d)&lt;br /&gt;
LSTYR=$(date +%Y --date=&amp;quot;-1 day&amp;quot;)&lt;br /&gt;
LSTMNTH=$(date +%m --date=&amp;quot;-1 day&amp;quot;)&lt;br /&gt;
LSTDAY=$(date +%d --date=&amp;quot;-1 day&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
## Let&amp;#039;s set up our directory system:&lt;br /&gt;
&lt;br /&gt;
if [ ! -d $WRKDIR ]; then&lt;br /&gt;
        mkdir $WRKDIR;&lt;br /&gt;
fi&lt;br /&gt;
if [ ! -d $WRKDIR/$YR ]; then&lt;br /&gt;
        mkdir $WRKDIR/$YR;&lt;br /&gt;
fi&lt;br /&gt;
if [ ! -d $WRKDIR/$YR/$MNTH ]; then&lt;br /&gt;
        mkdir $WRKDIR/$YR/$MNTH;&lt;br /&gt;
fi&lt;br /&gt;
if [ ! -d $WRKDIR/$YR/$MNTH ]; then&lt;br /&gt;
        mkdir $WRKDIR/$YR/$MNTH;&lt;br /&gt;
fi&lt;br /&gt;
if [ ! -d $WRKDIR/$YR/$MNTH/$DAY ]; then&lt;br /&gt;
        mkdir $WRKDIR/$YR/$MNTH/$DAY;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
## Lets make a working dir variable for yesterday and today&lt;br /&gt;
&lt;br /&gt;
CURWRKDIR=$WRKDIR/$YR/$MNTH/$DAY&lt;br /&gt;
LSTWRKDIR=$WRKDIR/$LSTYR/$LSTMNTH/$LSTDAY&lt;br /&gt;
&lt;br /&gt;
## Now we need to put some data in these directories.  This will populate all the LAN IPT data:&lt;br /&gt;
&lt;br /&gt;
for NUM in $(seq $NETNUM); do&lt;br /&gt;
LAN=$(eval echo \$LAN$NUM)&lt;br /&gt;
NNM=$(eval echo \$NNM$NUM)&lt;br /&gt;
	&lt;br /&gt;
	## If this is the first run of the day, this stanza will create our directory and bring forward totals from the previous day.&lt;br /&gt;
&lt;br /&gt;
       	if [ ! -d $CURWRKDIR/$LAN ]; then &lt;br /&gt;
		mkdir $CURWRKDIR/$LAN&lt;br /&gt;
		if [[ $(ls $CURWRKDIR/$LAN/*.in) == &amp;quot;&amp;quot; ]]; then&lt;br /&gt;
			if [[ $(ls $LSTWRKDIR/$LAN/*.in) != &amp;quot;&amp;quot; ]]; then&lt;br /&gt;
				cp $LSTWRKDIR/$LAN/*.in $CURWRKDIR/$LAN/&lt;br /&gt;
			fi&lt;br /&gt;
		fi&lt;br /&gt;
		if [[ $(ls $CURWRKDIR/$LAN/*.out) == &amp;quot;&amp;quot; ]]; then&lt;br /&gt;
			if [[ $(ls $LSTWRKDIR/$LAN/*.out) != &amp;quot;&amp;quot; ]]; then&lt;br /&gt;
				cp $LSTWRKDIR/$LAN/*.out $CURWRKDIR/$LAN/&lt;br /&gt;
			fi&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
	## Move last run&amp;#039;s data into the .old files&lt;br /&gt;
&lt;br /&gt;
	if [[ $(ls $CURWRKDIR/$LAN/*.in) != &amp;quot;&amp;quot; ]]; then&lt;br /&gt;
		for MVIN in $(ls $CURWRKDIR/$LAN/*.in); do &lt;br /&gt;
			mv $MVIN $MVIN.old&lt;br /&gt;
		done&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ $(ls $CURWRKDIR/$LAN/*.out) != &amp;quot;&amp;quot; ]]; then&lt;br /&gt;
		for MVOUT in $(ls $CURWRKDIR/$LAN/*.out); do &lt;br /&gt;
			mv $MVOUT $MVOUT.old&lt;br /&gt;
		done&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
	## Populate this run&amp;#039;s data.&lt;br /&gt;
&lt;br /&gt;
       	for DATA in $($DOIPT -l $NNM -s | grep $LAN); do&lt;br /&gt;
               	FN=$(echo $DATA | cut -f 1 -d \;)&lt;br /&gt;
               	echo $DATA | cut -f 3 -d \; &amp;gt; $CURWRKDIR/$LAN/$FN.in&lt;br /&gt;
               	echo $DATA | cut -f 5 -d \; &amp;gt; $CURWRKDIR/$LAN/$FN.out&lt;br /&gt;
       	done&lt;br /&gt;
	for RT in $(ls $CURWRKDIR/$LAN/*.in); do&lt;br /&gt;
		HOST=$(basename $RT .in)&lt;br /&gt;
		NEWIN=$(cat $CURWRKDIR/$LAN/$HOST.in)&lt;br /&gt;
		if [ ! -e $CURWRKDIR/$LAN/$HOST.in.old ]; then&lt;br /&gt;
			echo 0 &amp;gt; $CURWRKDIR/$LAN/$HOST.in.old&lt;br /&gt;
		fi&lt;br /&gt;
		OLDIN=$(cat $CURWRKDIR/$LAN/$HOST.in.old)&lt;br /&gt;
		if [[ $NEWIN -lt $OLDIN ]]; then&lt;br /&gt;
			NEWIN=$(( $NEWIN + $IPTWRAP ))&lt;br /&gt;
		fi&lt;br /&gt;
		NEWOUT=$(cat $CURWRKDIR/$LAN/$HOST.out)&lt;br /&gt;
		if [ ! -e $CURWRKDIR/$LAN/$HOST.out.old ]; then&lt;br /&gt;
			echo 0 &amp;gt; $CURWRKDIR/$LAN/$HOST.out.old&lt;br /&gt;
		fi&lt;br /&gt;
		OLDOUT=$(cat $CURWRKDIR/$LAN/$HOST.out.old)&lt;br /&gt;
		if [[ $NEWOUT -lt $OLDOUT ]]; then&lt;br /&gt;
			NEWOUT=$(( $NEWOUT + $IPTWRAP ))&lt;br /&gt;
		fi&lt;br /&gt;
		RUNIN=$(( $NEWIN - $OLDIN ))&lt;br /&gt;
		RUNOUT=$(( $NEWOUT - $OLDOUT ))&lt;br /&gt;
		echo &amp;quot;$LOGDT;$RUNIN;$RUNOUT&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/$LAN/$HOST.rt&lt;br /&gt;
	done &lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
## This will give IPT data for external interface&lt;br /&gt;
## First, check if this is first run today and if it is set up directory and bring last data forward&lt;br /&gt;
&lt;br /&gt;
if [ ! -d $CURWRKDIR/WAN ]; then&lt;br /&gt;
	mkdir $CURWRKDIR/WAN&lt;br /&gt;
	if [ ! -e $CURWRKDIR/WAN/wan ]; then&lt;br /&gt;
		if [ -e $LSTWRKDIR/WAN/wan ]; then&lt;br /&gt;
			cp $LSTWRKDIR/WAN/wan $CURWRKDIR/WAN/&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
fi&lt;br /&gt;
if [ -e $CURWRKDIR/WAN/wan ]; then&lt;br /&gt;
	mv $CURWRKDIR/WAN/wan $CURWRKDIR/WAN/wan.old&lt;br /&gt;
else&lt;br /&gt;
	echo 0 &amp;gt; $CURWRKDIR/WAN/wan.old&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
## Now populate the current data:&lt;br /&gt;
&lt;br /&gt;
$DOIPT -l wan | grep bytes | cut -f 4 -d : | cut -f 2 -d &amp;quot; &amp;quot; &amp;gt; $CURWRKDIR/WAN/wan&lt;br /&gt;
NEWWAN=$(cat $CURWRKDIR/WAN/wan)&lt;br /&gt;
OLDWAN=$(cat $CURWRKDIR/WAN/wan.old)&lt;br /&gt;
if [[ $NEWWAN -lt $OLDWAN ]]; then&lt;br /&gt;
	NEWWAN=$(( $NEWWAN + $IPTWRAP ))&lt;br /&gt;
fi&lt;br /&gt;
RUNWAN=$(echo &amp;quot;$NEWWAN - $OLDWAN&amp;quot; | bc)&lt;br /&gt;
echo &amp;quot;$LOGDT;$NEWWAN;$OLDWAN;$RUNWAN&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/WAN/wan.rt&lt;br /&gt;
&lt;br /&gt;
## This is to give raw egress/ingress data on internal interfaces&lt;br /&gt;
&lt;br /&gt;
for NUM in $(seq $NETNUM); do&lt;br /&gt;
	IF=$(eval echo \$IF$NUM)&lt;br /&gt;
&lt;br /&gt;
	## Test if this is first run, if it is, make the directory and bring last day&amp;#039;s data forward.&lt;br /&gt;
&lt;br /&gt;
	if [ ! -d $CURWRKDIR/IFACE ]; then&lt;br /&gt;
		mkdir $CURWRKDIR/IFACE&lt;br /&gt;
	fi&lt;br /&gt;
	if [ ! -e $CURWRKDIR/IFACE/$IF.in ]; then&lt;br /&gt;
		if [ -e $LSTWRKDIR/IFACE/$IF.in ]; then&lt;br /&gt;
			cp $LSTWRKDIR/IFACE/$IF.in $CURWRKDIR/IFACE/&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
	if [ ! -e $CURWRKDIR/IFACE/$IF.out ]; then&lt;br /&gt;
		if [ -e $LSTWRKDIR/IFACE/$IF.out ]; then&lt;br /&gt;
			cp $LSTWRKDIR/IFACE/$IF.out $CURWRKDIR/IFACE/&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
	if [ -e $CURWRKDIR/IFACE/$IF.in ]; then&lt;br /&gt;
		mv $CURWRKDIR/IFACE/$IF.in $CURWRKDIR/IFACE/$IF.in.old&lt;br /&gt;
	else&lt;br /&gt;
		echo 0 &amp;gt; $CURWRKDIR/IFACE/$IF.in.old&lt;br /&gt;
	fi&lt;br /&gt;
	if [ -e $CURWRKDIR/IFACE/$IF.out ]; then&lt;br /&gt;
		mv $CURWRKDIR/IFACE/$IF.out $CURWRKDIR/IFACE/$IF.out.old&lt;br /&gt;
	else&lt;br /&gt;
		echo 0 &amp;gt; $CURWRKDIR/IFACE/$IF.out.old&lt;br /&gt;
	fi&lt;br /&gt;
	cat /sys/class/net/$IF/statistics/rx_bytes &amp;gt; $CURWRKDIR/IFACE/$IF.in&lt;br /&gt;
	cat /sys/class/net/$IF/statistics/tx_bytes &amp;gt; $CURWRKDIR/IFACE/$IF.out&lt;br /&gt;
	NEWRX=$(cat $CURWRKDIR/IFACE/$IF.in)&lt;br /&gt;
	NEWTX=$(cat $CURWRKDIR/IFACE/$IF.out)&lt;br /&gt;
	OLDRX=$(cat $CURWRKDIR/IFACE/$IF.in.old)&lt;br /&gt;
	OLDTX=$(cat $CURWRKDIR/IFACE/$IF.out.old)&lt;br /&gt;
	if [[ $NEWRX -lt $OLDRX ]]; then&lt;br /&gt;
		NEWRX=$(( $NEWRX + $NETWRAP ))&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ $NEWTX -lt $OLDTX ]]; then&lt;br /&gt;
		NEWTX=$(( $NEWTX + $NETWRAP ))&lt;br /&gt;
	fi&lt;br /&gt;
	RUNRX=$(( $NEWRX - $OLDRX ))&lt;br /&gt;
	RUNTX=$(( $NEWTX - $OLDTX ))&lt;br /&gt;
	echo &amp;quot;$LOGDT;$RUNRX;$RUNTX&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/IFACE/$IF.rt&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
## Now we need egress/ingress for the wan&lt;br /&gt;
&lt;br /&gt;
if [ ! -e $CURWRKDIR/IFACE/$WAN.in ]; then&lt;br /&gt;
	if [ -e $LSTWRKDIR/IFACE/$WAN.in ]; then&lt;br /&gt;
		cp $LSTWRKDIR/IFACE/$WAN.in $CURWRKDIR/IFACE/&lt;br /&gt;
	fi&lt;br /&gt;
fi&lt;br /&gt;
if [ ! -e $CURWRKDIR/IFACE/$WAN.out ]; then&lt;br /&gt;
	if [ -e $LSTWRKDIR/IFACE/$WAN.out ]; then&lt;br /&gt;
		cp $LSTWRKDIR/IFACE/$WAN.out $CURWRKDIR/IFACE/&lt;br /&gt;
	fi&lt;br /&gt;
fi&lt;br /&gt;
if [ -e $CURWRKDIR/IFACE/$WAN.in ]; then&lt;br /&gt;
	mv $CURWRKDIR/IFACE/$WAN.in $CURWRKDIR/IFACE/$WAN.in.old&lt;br /&gt;
else&lt;br /&gt;
	echo 0 &amp;gt; $CURWRKDIR/IFACE/$WAN.in.old&lt;br /&gt;
fi&lt;br /&gt;
if [ -e $CURWRKDIR/IFACE/$WAN.out ]; then&lt;br /&gt;
	mv $CURWRKDIR/IFACE/$WAN.out $CURWRKDIR/IFACE/$WAN.out.old&lt;br /&gt;
else&lt;br /&gt;
	echo 0 &amp;gt; $CURWRKDIR/IFACE/$WAN.out.old&lt;br /&gt;
fi&lt;br /&gt;
cat /sys/class/net/$WAN/statistics/rx_bytes &amp;gt; $CURWRKDIR/IFACE/$WAN.in&lt;br /&gt;
cat /sys/class/net/$WAN/statistics/tx_bytes &amp;gt; $CURWRKDIR/IFACE/$WAN.out&lt;br /&gt;
NEWRX=$(cat $CURWRKDIR/IFACE/$WAN.in)&lt;br /&gt;
NEWTX=$(cat $CURWRKDIR/IFACE/$WAN.out)&lt;br /&gt;
OLDRX=$(cat $CURWRKDIR/IFACE/$WAN.in.old)&lt;br /&gt;
OLDTX=$(cat $CURWRKDIR/IFACE/$WAN.out.old)&lt;br /&gt;
if [[ $NEWRX -lt $OLDRX ]]; then&lt;br /&gt;
	NEWRX=$(( $NEWRX + $NETWRAP ))&lt;br /&gt;
fi&lt;br /&gt;
if [[ $NEWTX -lt $OLDTX ]]; then&lt;br /&gt;
	NEWTX=$(( $NEWTX + $NETWRAP ))&lt;br /&gt;
fi&lt;br /&gt;
RUNRX=$(( $NEWRX - $OLDRX ))&lt;br /&gt;
RUNTX=$(( $NEWTX - $OLDTX ))&lt;br /&gt;
echo &amp;quot;$LOGDT;$RUNRX;$RUNTX&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/IFACE/$WAN.rt&lt;br /&gt;
&lt;br /&gt;
## Whew!! that should provide us all the raw data we need to generate some totals and put a report together.&lt;br /&gt;
## We want all of the above to run frequently enough that neither of the *WRAP variables is exceeded&lt;br /&gt;
## From this point, we start calculating daily totals and generating reports&lt;br /&gt;
&lt;br /&gt;
## We only want to generate totals once per day.  In this case, when CURHOUR is now.&lt;br /&gt;
## Make sure to not delete the matching fi statement at the end of the script:&lt;br /&gt;
&lt;br /&gt;
if [[ $CURHOUR == $TTLNOW ]]; then&lt;br /&gt;
&lt;br /&gt;
## First lets generate totals from our interface data.&lt;br /&gt;
&lt;br /&gt;
for TIF in $(ls $CURWRKDIR/IFACE/*.rt); do&lt;br /&gt;
	while read ETH; do&lt;br /&gt;
		RAWIN=$(echo $ETH | cut -f 2 -d \;)&lt;br /&gt;
		RAWOUT=$(echo $ETH | cut -f 3 -d \;)&lt;br /&gt;
		TTLIN=$(( $TTLIN + $RAWIN ))&lt;br /&gt;
		TTLOUT=$(( $TTLOUT + $RAWOUT ))&lt;br /&gt;
	done &amp;lt; $TIF&lt;br /&gt;
	DTTL=$(( $TTLIN + $TTLOUT ))&lt;br /&gt;
	IFN=$(basename $TIF .rt)&lt;br /&gt;
	echo &amp;quot;$IFN;$TTLIN;$TTLOUT;$DTTL&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/ttl.iface&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
## This will total up the ipt count for the external interface&lt;br /&gt;
&lt;br /&gt;
while read TWAN; do&lt;br /&gt;
	CNTWAN=$(echo $TWAN | cut -f 4 -d \;)&lt;br /&gt;
	TTLWAN=$(echo &amp;quot;$TTLWAN + $CNTWAN&amp;quot; | bc)&lt;br /&gt;
done &amp;lt; $CURWRKDIR/WAN/wan.rt&lt;br /&gt;
echo $TTLWAN &amp;gt; $CURWRKDIR/ttl.wan&lt;br /&gt;
&lt;br /&gt;
## Now we need to bring everythign together for the internal interface&lt;br /&gt;
&lt;br /&gt;
for NUM in $(seq $NETNUM); do&lt;br /&gt;
	STIPTOUT=0&lt;br /&gt;
	STIPTIN=0&lt;br /&gt;
	STIPT=0&lt;br /&gt;
	LAN=$(eval echo \$LAN$NUM)&lt;br /&gt;
	NNM=$(eval echo \$NNM$NUM)&lt;br /&gt;
	for TLAN in $(ls $CURWRKDIR/$LAN/*.rt); do&lt;br /&gt;
		TIPTIN=0&lt;br /&gt;
		TIPTOUT=0&lt;br /&gt;
		while read IPT; do&lt;br /&gt;
			IPTIN=$(echo $IPT | cut -f 2 -d \;)&lt;br /&gt;
			IPTOUT=$(echo $IPT | cut -f 3 -d \;)&lt;br /&gt;
			TIPTIN=$(( $TIPTIN + $IPTIN ))&lt;br /&gt;
			TIPTOUT=$(( $TIPTOUT + $IPTOUT ))&lt;br /&gt;
		done &amp;lt; $TLAN&lt;br /&gt;
		TIPT=$(( $TIPTIN + $TIPTOUT ))&lt;br /&gt;
		TFN=$(basename $TLAN .rt)&lt;br /&gt;
		echo &amp;quot;$TFN;$TIPTIN;$TIPTOUT;$TIPT&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/rpt.$NNM&lt;br /&gt;
		STIPTIN=$(( $STIPTIN + $TIPTIN ))&lt;br /&gt;
		STIPTOUT=$(( $STIPTOUT + $TIPTOUT ))&lt;br /&gt;
	done&lt;br /&gt;
	STIPT=$(( $STIPTIN + $STIPTOUT ))&lt;br /&gt;
	echo &amp;quot;$LAN;$STIPTIN;$STIPTOUT;$STIPT&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/ttl.lan&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
## Now we need to create some month-to-date stats&lt;br /&gt;
&lt;br /&gt;
for MTD in $(ls $WRKDIR/$YR/$MNTH); do&lt;br /&gt;
	MTDIPTWAN=$(cat $WRKDIR/$YR/$MNTH/$MTD/ttl.wan)&lt;br /&gt;
	TMTDIPTWAN=$(echo &amp;quot;$TMTDIPTWAN + $MTDIPTWAN&amp;quot; | bc)&lt;br /&gt;
	MTDRAWWANIN=$(cat $WRKDIR/$YR/$MNTH/$MTD/ttl.iface | grep $WAN | cut -f 2 -d \;)&lt;br /&gt;
	TMTDRAWWANIN=$(echo &amp;quot;$TMTDRAWWANIN + $MTDRAWWANIN&amp;quot; | bc)&lt;br /&gt;
	MTDRAWWANOUT=$(cat $WRKDIR/$YR/$MNTH/$MTD/ttl.iface | grep $WAN | cut -f 3 -d \;)&lt;br /&gt;
	TMTDRAWWANOUT=$(echo &amp;quot;$TMTDRAWWANOUT + $MTDRAWWANOUT&amp;quot; | bc)&lt;br /&gt;
	MTDRAWWAN=$(cat $WRKDIR/$YR/$MNTH/$MTD/ttl.iface | grep $WAN | cut -f 4 -d \;)&lt;br /&gt;
	TMTDRAWWAN=$(echo &amp;quot;$TMTDRAWWAN + $MTDRAWWAN&amp;quot; | bc)&lt;br /&gt;
	echo &amp;quot;IPT;$TMTDIPTWAN;RAW;$TMTDRAWWANIN;$TMTDRAWWANOUT;$TMTDRAWWAN&amp;quot; &amp;gt; $CURWRKDIR/mtd.$WAN&lt;br /&gt;
	for NUM in $(seq $NETNUM); do&lt;br /&gt;
		IF=$(eval echo \$IF$NUM)&lt;br /&gt;
		MTDIFIN=$(cat $WRKDIR/$YR/$MNTH/$MTD/ttl.iface | grep $IF | cut -f 2 -d \;)&lt;br /&gt;
		TMTDIFIN=$(echo &amp;quot;$TMTDIFIN + $MTDIFIN&amp;quot; | bc)&lt;br /&gt;
		MTDIFOUT=$(cat $WRKDIR/$YR/$MNTH/$MTD/ttl.iface | grep $IF | cut -f 3 -d \;)&lt;br /&gt;
		TMTDIFOUT=$(echo &amp;quot;$TMTDIFOUT + $MTDIFOUT&amp;quot; | bc)&lt;br /&gt;
		MTDIF=$(cat $WRKDIR/$YR/$MNTH/$MTD/ttl.iface | grep $IF | cut -f 4 -d \;)&lt;br /&gt;
		TMTDIF=$(echo &amp;quot;$TMTDIF + $MTDIF&amp;quot; | bc)&lt;br /&gt;
		echo &amp;quot;$TMTDIFIN;$TMTDIFOUT;$TMTDIF&amp;quot; &amp;gt; $CURWRKDIR/mtd.$IF&lt;br /&gt;
	done&lt;br /&gt;
	for NUM in $(seq $NETNUM); do&lt;br /&gt;
		LAN=$(eval echo \$LAN$NUM)&lt;br /&gt;
		MTDLANIN=$(cat $WRKDIR/$YR/$MNTH/$MTD/ttl.lan | grep $LAN | cut -f 2 -d \;)&lt;br /&gt;
		TMTDLANIN=$(echo &amp;quot;$TMTDLANIN + $MTDLANIN&amp;quot; | bc)&lt;br /&gt;
		MTDLANOUT=$(cat $WRKDIR/$YR/$MNTH/$MTD/ttl.lan | grep $LAN | cut -f 3 -d \;)&lt;br /&gt;
		TMTDLANOUT=$(echo &amp;quot;$TMTDLANOUT + $MTDLANOUT&amp;quot; | bc)&lt;br /&gt;
		MTDLAN=$(cat $WRKDIR/$YR/$MNTH/$MTD/ttl.lan | grep $LAN | cut -f 4 -d \;)&lt;br /&gt;
		TMTDLAN=$(echo &amp;quot;$TMTDLAN + $MTDLAN&amp;quot; | bc)&lt;br /&gt;
		echo &amp;quot;$TMTDLANIN;$TMTDLANOUT;$TMTDLAN&amp;quot; &amp;gt; $CURWRKDIR/mtd.$LAN&lt;br /&gt;
	done&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
## Now that we have totals, we will make a few final calculations to put in our report.&lt;br /&gt;
## The lan parts of the report will be calculated and reported on the fly so they can be in loops&lt;br /&gt;
## First thing; Percentage of allowable bandwidth consumed this month&lt;br /&gt;
&lt;br /&gt;
ABITS=$(( $USAGE * $DIV * $DIV * $DIV ))&lt;br /&gt;
UBITS=$(cat $CURWRKDIR/mtd.$WAN | cut -f 6 -d \;)&lt;br /&gt;
PBITS=$(echo &amp;quot;scale=2; $UBITS * 100 / $ABITS&amp;quot; | bc)&lt;br /&gt;
&lt;br /&gt;
## Convert daily WAN stats to MB:&lt;br /&gt;
&lt;br /&gt;
IWANRAW=$(cat $CURWRKDIR/ttl.iface | grep $WAN | cut -f 2 -d \;)&lt;br /&gt;
IWANRAWMB=$(echo &amp;quot;$IWANRAW / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
OWANRAW=$(cat $CURWRKDIR/ttl.iface | grep $WAN | cut -f 3 -d \;)&lt;br /&gt;
OWANRAWMB=$(echo &amp;quot;$OWANRAW / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
TWANRAW=$(cat $CURWRKDIR/ttl.iface | grep $WAN | cut -f 4 -d \;)&lt;br /&gt;
TWANRAWMB=$(echo &amp;quot;$TWANRAW / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
WANIPT=$(cat $CURWRKDIR/ttl.wan)&lt;br /&gt;
WANIPTMB=$(echo &amp;quot;$WANIPT / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
&lt;br /&gt;
## Convert mtd WAN stats to MB&lt;br /&gt;
&lt;br /&gt;
IMTDWANRAW=$(cat $CURWRKDIR/mtd.$WAN | cut -f 4 -d \;)&lt;br /&gt;
IMTDWANRAWMB=$(echo &amp;quot;$IMTDWANRAW / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
OMTDWANRAW=$(cat $CURWRKDIR/mtd.$WAN | cut -f 5 -d \;)&lt;br /&gt;
OMTDWANRAWMB=$(echo &amp;quot;$OMTDWANRAW / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
TMTDWANRAW=$(cat $CURWRKDIR/mtd.$WAN | cut -f 6 -d \;)&lt;br /&gt;
TMTDWANRAWMB=$(echo &amp;quot;$TMTDWANRAW / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
MTDWANIPT=$(cat $CURWRKDIR/mtd.$WAN | cut -f 2 -d \;)&lt;br /&gt;
MTDWANIPTMB=$(echo &amp;quot;$MTDWANIPT / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
&lt;br /&gt;
## Let&amp;#039;s start the report by generating a header and appending it to today&amp;#039;s report file:&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;========================================================================&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;Bandwidth Report generated at end of this day:		$YR-$MNTH-$DAY&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;========================================================================&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;========================================================================&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;SUMMARY&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;========================================================================&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;Percentage of allowable bandwidth usage this month :	$PBITS %&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;Egress/Ingress(1) external usage today in MegaBytes:	$TWANRAWMB MB&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;Egress/Ingress(1) external usage this Month To Date:	$TMTDWANRAWMB MB&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
for NUM in $(seq $NETNUM); do&lt;br /&gt;
	LAN=$(eval echo \$LAN$NUM)&lt;br /&gt;
	NNM=$(eval echo \$NNM$NUM)&lt;br /&gt;
	LANIPT=$(cat $CURWRKDIR/ttl.lan | grep $LAN | cut -f 4 -d \;)&lt;br /&gt;
	LANIPTMB=$(echo &amp;quot;$LANIPT / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
	MTDLANIPT=$(cat $CURWRKDIR/mtd.$LAN | cut -f 3 -d \;)&lt;br /&gt;
	MTDLANIPTMB=$(echo &amp;quot;$MTDLANIPT / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
	echo &amp;quot;Accounted(2) $NNM usage today in MegaBytes:		$LANIPTMB MB&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	echo &amp;quot;Accounted(2) $NNM usage this Month To Date:		$MTDLANIPTMB MB&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;========================================================================&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;External Network - Upload/Download(3) Detailed Report&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;========================================================================&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
printf &amp;quot;%-33s %-16s %-16s %-20s\n&amp;quot; &amp;quot;Detail&amp;quot; &amp;quot;DOWN&amp;quot; &amp;quot;UP&amp;quot; &amp;quot;TOTAL&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
printf &amp;quot;%-33s %-16s %-16s %-20s\n&amp;quot; &amp;quot;Egress/Ingress(1) Today (MB): &amp;quot; &amp;quot;$IWANRAWMB&amp;quot; &amp;quot;$OWANRAWMB&amp;quot; &amp;quot;$TWANRAWMB&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
printf &amp;quot;%-33s %-16s %-16s %-20s\n&amp;quot; &amp;quot;                    In Bytes: &amp;quot; $IWANRAW $OWANRAW $TWANRAW &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
printf &amp;quot;%-33s %-16s %-16s %-20s\n&amp;quot; &amp;quot;Egress/Ingress(1) This Month: &amp;quot; &amp;quot;$IMTDWANRAWMB&amp;quot; &amp;quot;$OMTDWANRAWMB&amp;quot; &amp;quot;$TMTDWANRAWMB&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
printf &amp;quot;%-33s %-16s %-16s %-20s\n&amp;quot; &amp;quot;                    In Bytes: &amp;quot; $IMTDWANRAW $OMTDWANRAW $TMTDWANRAW &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
printf &amp;quot;%-33s %-16s %-16s\n&amp;quot; &amp;quot;Detail(4)&amp;quot; &amp;quot;BYTES:&amp;quot; &amp;quot;MEGABYTES:&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
printf &amp;quot;%-33s %-16s %-16s\n&amp;quot; &amp;quot;Accounted(2)         Today: &amp;quot; $WANIPT $WANIPTMB &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
printf &amp;quot;%-33s %-16s %-16s\n&amp;quot; &amp;quot;Accounted(2)    This Month: &amp;quot; $MTDWANIPT $MTDWANIPTMB &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
&lt;br /&gt;
## set up a loop so each network segment can be reported:&lt;br /&gt;
&lt;br /&gt;
for NUM in $(seq $NETNUM); do&lt;br /&gt;
	LAN=$(eval echo \$LAN$NUM)&lt;br /&gt;
	IF=$(eval echo \$IF$NUM)&lt;br /&gt;
	NNM=$(eval echo \$NNM$NUM)&lt;br /&gt;
&lt;br /&gt;
	## This pile of variables will grab the numbers from the data for each network&lt;br /&gt;
&lt;br /&gt;
	ILANRAW=$(cat $CURWRKDIR/ttl.iface | grep $IF | cut -f 2 -d \;)&lt;br /&gt;
	ILANRAWMB=$(echo &amp;quot;$ILANRAW / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
	OLANRAW=$(cat $CURWRKDIR/ttl.iface | grep $IF | cut -f 3 -d \;)&lt;br /&gt;
	OLANRAWMB=$(echo &amp;quot;$OLANRAW / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
	TLANRAW=$(cat $CURWRKDIR/ttl.iface | grep $IF | cut -f 4 -d \;)&lt;br /&gt;
	TLANRAWMB=$(echo &amp;quot;$TLANRAW / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
	ILANIPT=$(cat $CURWRKDIR/ttl.lan | grep $LAN | cut -f 2 -d \;)&lt;br /&gt;
	ILANIPTMB=$(echo &amp;quot;$ILANIPT / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
	OLANIPT=$(cat $CURWRKDIR/ttl.lan | grep $LAN | cut -f 3 -d \;)&lt;br /&gt;
	OLANIPTMB=$(echo &amp;quot;$OLANIPT / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
	TLANIPT=$(cat $CURWRKDIR/ttl.lan | grep $LAN | cut -f 4 -d \;)&lt;br /&gt;
	TLANIPTMB=$(echo &amp;quot;$TLANIPT / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
	IMTDLANRAW=$(cat $CURWRKDIR/mtd.$IF | cut -f 1 -d \;)&lt;br /&gt;
	IMTDLANRAWMB=$(echo &amp;quot;$IMTDLANRAW / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
	OMTDLANRAW=$(cat $CURWRKDIR/mtd.$IF | cut -f 2 -d \;)&lt;br /&gt;
	OMTDLANRAWMB=$(echo &amp;quot;$OMTDLANRAW / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
	TMTDLANRAW=$(cat $CURWRKDIR/mtd.$IF | cut -f 3 -d \;)&lt;br /&gt;
	TMTDLANRAWMB=$(echo &amp;quot;$TMTDLANRAW / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
	IMTDLANIPT=$(cat $CURWRKDIR/mtd.$LAN | cut -f 1 -d \;)&lt;br /&gt;
	IMTDLANIPTMB=$(echo &amp;quot;$IMTDLANIPT / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
	OMTDLANIPT=$(cat $CURWRKDIR/mtd.$LAN | cut -f 2 -d \;)&lt;br /&gt;
	OMTDLANIPTMB=$(echo &amp;quot;$OMTDLANIPT / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
	TMTDLANIPT=$(cat $CURWRKDIR/mtd.$LAN | cut -f 3 -d \;)&lt;br /&gt;
	TMTDLANIPTMB=$(echo &amp;quot;$TMTDLANIPT / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
&lt;br /&gt;
	## And now we can present that in a nice little table for each network&lt;br /&gt;
&lt;br /&gt;
	echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	echo &amp;quot;========================================================================&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	echo &amp;quot;$NNM Network - Upload/Download(3) Detailed Report&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	echo &amp;quot;========================================================================&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	printf &amp;quot;%-33s %-16s %-16s %-20s\n&amp;quot; &amp;quot;Detail&amp;quot; &amp;quot;DOWN&amp;quot; &amp;quot;UP&amp;quot; &amp;quot;TOTAL&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	printf &amp;quot;%-33s %-16s %-16s %-20s\n&amp;quot; &amp;quot;Egress/Ingress(1) Today (MB): &amp;quot; $OLANRAWMB $ILANRAWMB $TLANRAWMB &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	printf &amp;quot;%-33s %-16s %-16s %-20s\n&amp;quot; &amp;quot;                    In Bytes: &amp;quot; $OLANRAW $ILANRAW $TLANRAW &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	printf &amp;quot;%-33s %-16s %-16s %-20s\n&amp;quot; &amp;quot;Egress/Ingress(1) This Month: &amp;quot; $OMTDLANRAWMB $IMTDLANRAWMB $TMTDLANRAWMB &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	printf &amp;quot;%-33s %-16s %-16s %-20s\n&amp;quot; &amp;quot;                    In Bytes: &amp;quot; $OMTDLANRAW $IMTDLANRAW $TMTDLANRAW &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	printf &amp;quot;%-33s %-16s %-16s %-20s\n&amp;quot; &amp;quot;Accounted(2)      Today (MB): &amp;quot; $OLANIPTMB $ILANIPTMB $TLANIPTMB &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	printf &amp;quot;%-33s %-16s %-16s %-20s\n&amp;quot; &amp;quot;                    In Bytes: &amp;quot; $OLANIPT  $ILANIPT $TLANIPT &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	printf &amp;quot;%-33s %-16s %-16s %-20s\n&amp;quot; &amp;quot;Accounted(2)      This Month: &amp;quot; $OMTDLANIPTMB $IMTDLANIPTMB $TMTDLANIPTMB &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	printf &amp;quot;%-33s %-16s %-16s %-20s\n&amp;quot; &amp;quot;                    In Bytes: &amp;quot; $OMTDLANIPT $IMTDLANIPT $TMTDLANIPT &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt	&lt;br /&gt;
	echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
&lt;br /&gt;
	## Now we have to chop up the rpt.* files and present them in the report.&lt;br /&gt;
&lt;br /&gt;
	printf &amp;quot;%-20s %-20s %-10s %-10s %-15s\n&amp;quot; &amp;quot;Host:&amp;quot; &amp;quot;IP:&amp;quot; &amp;quot;DOWN:&amp;quot; &amp;quot;UP:&amp;quot; &amp;quot;TOTAL:&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
#	echo &amp;quot;Host:			IP:			DOWN:		UP:			TOTAL:&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
	while read RPT; do&lt;br /&gt;
		IP=$(echo $RPT | cut -f 1 -d \;)&lt;br /&gt;
		IPIN=$(echo $RPT | cut -f 2 -d \;)&lt;br /&gt;
		IPINMB=$(echo &amp;quot;$IPIN / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
		IPOUT=$(echo $RPT | cut -f 3 -d \;)&lt;br /&gt;
		IPOUTMB=$(echo &amp;quot;$IPOUT / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
		IPTOT=$(echo $RPT | cut -f 4 -d \;)&lt;br /&gt;
		IPTOTMB=$(echo &amp;quot;$IPTOT / $DIV / $DIV&amp;quot; | bc)&lt;br /&gt;
		&lt;br /&gt;
		## Try some hostname detection&lt;br /&gt;
&lt;br /&gt;
		if [[ $IPTOTMB != &amp;quot;0&amp;quot; ]]; then&lt;br /&gt;
			HST=$($DONBT -s \! $IP | cut -f 2 -d \!)&lt;br /&gt;
			if [[ $HST == &amp;quot;&amp;quot; ]]; then&lt;br /&gt;
				HST=&amp;quot;Not Available&amp;quot;&lt;br /&gt;
			fi&lt;br /&gt;
#			echo &amp;quot;$HST		$IP		$IPOUTMB		$IPINMB			$IPTOTMB&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
			printf &amp;quot;%-20s %-20s %-10s %-10s %-15s\n&amp;quot; &amp;quot;$HST&amp;quot; $IP &amp;quot;$IPOUTMB MB&amp;quot; &amp;quot;$IPINMB MB&amp;quot; &amp;quot;$IPTOTMB MB&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
			echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
		fi&lt;br /&gt;
	done &amp;lt; $CURWRKDIR/rpt.$NNM&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;========================================================================&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;Foot Notes&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;========================================================================&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;(1) Egress is outgoing, Ingress is incoming&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;    This is a measure of bits passed between the firewall and the cable&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;    This number should match your ISP count&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;(2) Accounted traffic passes into or out of the firewall packet filter, and is&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;    expected to always be a little bit less than Egress/Ingress.  Unlike&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;    Egress and Ingress, this traffic can be filtered and therefor used to&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;    track usage by individuals on the LANs&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;(3) Upload/Download for this report relate the end user and are not from&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;    the point of view of the firewall.  In other words, Upload from the&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;    firewall to a LAN user will be reported as Download&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;(4) Accounted traffic on the external port does not differentiate direction.&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
echo &amp;quot;    Any packet from any IP address will be counted on the external port&amp;quot; &amp;gt;&amp;gt; $CURWRKDIR/daily.rpt&lt;br /&gt;
&lt;br /&gt;
## At last, all we have gathered data all day, generated some interesting information, and created a report.  &lt;br /&gt;
## No good leaving the report on the server, though, let&amp;#039;s mail it to someone, just for fun...&lt;br /&gt;
&lt;br /&gt;
env MAILRC=/dev/null from=$MLFRM mailx -n -s &amp;quot;Daily Bandwidth Report - $PBITS% Used this Month&amp;quot; $ADMINML &amp;lt; $CURWRKDIR/daily.rpt&lt;br /&gt;
&lt;br /&gt;
## This closes the if statement that determines if the daily totals should be calculated.  DO NOT DELETE THIS LINE:&lt;br /&gt;
&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bob</name></author>
	</entry>
</feed>