Date: 	Wed, 5 Jun 1996 15:29:07 +0200 (MET DST)
From: Eugenio Pierno <tomcat@netway.it>
Reply-To: pierno@netway.it
To: Ulrich Callmeier <uc@brian.lunetix.de>
Subject: net-acct 0.4 and my script

[ ... ]

I send you the script I'm using to extract and add ppp traffic.
It's very simple but works OK. I didn't write it in perl because I'm 
a perl beginner and I don't feel yet confortable. 
If you think this script can be of any usefulness please add it to your 
contrib directory, it's my vry little contribute to the wonderful Linux 
Community.

[ ... ]

---------------------- CUT HERE ----------------------
#!/bin/sh
#
#
# ppp-acct.sh -- Traffic accounting for dial-up ppp users. 
#
#
#
# Author: Eugenio Pierno, 1996.
# Email:  pierno@netway.it
# Organization: Netway Internet Provider 
# Location: Naples, Italy
#
#
# What is it?   This script is based on the output of net-acct-0.4
#               by Ulrich Callmeier (uc@brian.lunetix.de).
#               It is intended for a system where you need to know
#               exactly how much traffic every dial-up ppp user is
#               generating. 
#               It works on the assumption you have succesfully
#               configured the "dinamic slip/ppp" options in
#               /etc/nacctab. 
#
# How does it work?
#               It clears the default output file "net-acct" and
#               it does keep an updated value of the traffic of 
#               each dial-up ppp user creating a file "traffico"
#               in each user home directory.
#               The file will only contain the total amount of 
#               traffic the user has made since you started logging.  
#               Just make sure you are not accounting local
#               traffic but only ppp traffic (see the options
#               in /etc/nacctab). 
# 
# How to use it?
#         Simply put this script in /usr/local/bin and make an entry 
#         in your crontab which looks like:
#         * */1 * * *	exec /usr/local/bin/ppp-acct.sh >& /dev/null
#         This will execute the script every hour.
#
#


 
# Directory where the output file "net-acct" is kept.
# Adjust this to your site.
W3="/usr/var/acct/"

# Directory where the users' home directories are kept.
# In my system this is /usr/home
# Adjust this to your site.
W4="/usr/home/"

#---------------------------------------------
# Don't need to adjust anything from here down
#---------------------------------------------
 
# Work on a copy of the output file 
cp ${W3}net-acct ${W3}net-acct.tmp 
cat /dev/null > ${W3}net-acct

# Extract ppp lines from "net-acct" and put them in "ppp-acct" 
cat ${W3}net-acct.tmp | grep ppp | cut -f7,9 | sort +1 > ${W3}ppp-acct

# Delete temporary file
rm -f ${W3}net-acct.tmp

# Command Block which reads "ppp-acct" and puts ppp traffic in a file
# called "traffico" in each user home directory. 
# If the user had no previous traffic an empty file is created, otherwise 
# new traffic is added to old traffic.
{
   while read traffic login; do
     if [ -e ${W4}$login/traffico ]; then
        OLD_TRAFFIC=`cat ${W4}$login/traffico`
        declare -i SOMMA=`expr $OLD_TRAFFIC + $traffic`
        echo $SOMMA > ${W4}$login/traffico
     else
        echo $traffic > ${W4}$login/traffico
     fi
   done
} < ${W3}ppp-acct

# Remove ppp-acct
rm -f ${W3}ppp-acct

-------------------------- CUT HERE ---------------------------


~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~
   Eugenio Pierno                            Phone: + 81-7624433
   Network Administrator                     Fax:   + 81-7623909 
   Netway Internet Provider                  Email: pierno@netway.it
   ITnet Group, Naples, Italy                http://www.netway.it/
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~

ITnet is a member of PIPEX International.
ITnet is associated to CIX and RIPE. 
