Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!van-bc!twg!bill From: bill@twg.bc.ca (Bill Irwin) Newsgroups: comp.unix.admin Subject: Re: UUCP Accounting (source files) Message-ID: <861@twg.bc.ca> Date: 20 Feb 91 08:24:51 GMT References: <1991Feb17.222839.4406@hotmomma.UUCP> <811@twg.bc.ca> Reply-To: bill@twg.bc.ca (Bill Irwin) Organization: The Westrheim Group, Vancouver, B.C., Canada Lines: 257 bill@twg.bc.ca (Bill Irwin) writes: }I use an awk script I got from the net. It produces output like }so: }System Xfers Bytes rec Bytes xmt Connect Avg Xf Avg rec Avg xmt }van-bc 6 806928 0 1:01:55 134488 217 0 }TOTALS 6 806928 0 1:01:55 }TTY Connect % Data % }[ttyi1P] 01:01:55 100 806928 100% }This report is not very full because the daily report has already }run and the log files rotated, but you get the idea. If this }could be of use to you, mail me and I will mail it to you. Boy did I get a dump of requests in my mailbox for this! Here are the sources. One, "uucp_traffic" is just a shell script run manually. It will accept a file name as an argument and analyze it instead of the default. If you store your uucp xferstats into a monthly file, this file could be given as the argument and you would see the month's activity. The script "uucp_daily" is run from cron about 11:45 pm. It processes the days uucp xferstats file, mails the output and appends the file to a monthly log. The other file is the awk program that actually does the analysis and produces the report. Enjoy. ---- Cut Here and unpack ---- #!/bin/sh # This is a shell archive (shar 3.32) # made 02/20/1991 08:15 UTC by bill@TWG # Source directory /tmp/uucp.awk # # existing files WILL be overwritten # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 3168 -rw-rw-r-- uucp.awk # 266 -rwxrwxr-x uucp_daily # 233 -rwxrwxr-x uucp_traffic # if touch 2>&1 | fgrep 'amc' > /dev/null then TOUCH=touch else TOUCH=true fi # ============= uucp.awk ============== echo "x - extracting uucp.awk (Text)" sed 's/^X//' << 'SHAR_EOF' > uucp.awk && X# USAGE: awk -f syslog_awk /usr/spool/uucp/SYSLOG X# An awk script for printing a pretty report of UUCP activities from the X# UUCP SYSLOG - Erik E. Fair October 2, 1984 X# X# v7 UUCP X$4 == "received" { X sysname[$2] = $2; X by_rec[$2] += $6; X sec_rec[$2] += $8; X sys_xf[$2] ++; X} X# X# 4.2 BSD UUCP X$5 == "received" { X sysname[$2] = $2; X by_rec[$2] += $7; X sec_rec[$2] += $9; X sys_xf[$2] ++; X} X# X# System V UUCP X$6 == "<-" { X $1 = substr($1, 1, (index($1, "!") - 1)); X sysname[$1] = $1; X by_rec[$1] += $7; X sec_rec[$1] += $9; X sys_xf[$1] ++; X ttytime[$5] += $9; X ttyxfer[$5] += $7; X} X# X# v7 UUCP X$4 == "sent" { X sysname[$2] = $2; X by_xmt[$2] += $6; X sec_xmt[$2] += $8; X sys_xf[$2] ++; X} X# X# 4.2 BSD UUCP X$5 == "sent" { X sysname[$2] = $2; X by_xmt[$2] += $7; X sec_xmt[$2] += $9; X sys_xf[$2] ++; X} X# X# System V UUCP X$6 == "->" { X $1 = substr($1, 1, (index($1, "!") - 1)); X sysname[$1] = $1; X by_xmt[$1] += $7; X sec_xmt[$1] += $9; X sys_xf[$1] ++; X ttytime[$5] += $9; X ttyxfer[$5] += $7; X} XEND { X# X# print a report header X printf("System Xfers Bytes rec Bytes xmt Connect Avg Xf Avg rec Avg xmt\n") X for(i in sysname) { X# X# sort report by most connect time (selection sort) X first = 0; X for(j in sysname) { X if (sys_xf[j] > 0) { X tmp1 = sec_xmt[j]; X tmp2 = sec_rec[j]; X# Stupid AWK bug - needs a simple expression X time = (tmp1 + tmp2); X if (time > first) { X first = time; X sys = sysname[j]; X } X } X } X# X# 4.2 BSD awk seems to have problems. This check should not be necessary. X# Oddly enough, this problem also shows up in System V. WHY??? X if (sys_xf[sys] != 0) { X# X# time for some bean counting X tmp1 = sec_xmt[sys]; X tmp2 = sec_rec[sys]; X# Stupid AWK bug - needs a simple expression X time = (tmp1 + tmp2); X hours = time / 3600; X sec = time % 3600; X min = sec / 60; X sec %= 60; X tot_xf += sys_xf[sys]; X tot_by_rec += by_rec[sys]; X tot_by_xmt += by_xmt[sys]; X tot_time += time; X# X# protect myself against mathematical crime (divide by zero) X if (sec_rec[sys] == 0) X sec_rec[sys] = 1; X if (sec_xmt[sys] == 0) X sec_xmt[sys] = 1; X# X# print a pretty system report (god what an awful printf format...) X printf("%-8s%8d%11d%11d%4d:%.2d:%.2d%8d%9d%9d\n", \ Xsysname[sys], sys_xf[sys], by_rec[sys], by_xmt[sys], hours, min, sec, \ X((by_rec[sys] + by_xmt[sys]) / sys_xf[sys]), \ X(by_rec[sys] / sec_rec[sys]), \ X(by_xmt[sys] / sec_xmt[sys])); X# X# make certain we will not see this system again... (selection sort) X sys_xf[sys] = 0; X } X } X# X# calculate time split for total time (and print totals [*shudder*]) X hours = tot_time / 3600; X sec = tot_time % 3600; X min = sec / 60; X sec %= 60; X printf("\n%-8s%8d%11d%11d%4d:%.2d:%.2d\n", \ X "TOTALS", tot_xf, tot_by_rec, tot_by_xmt, hours, min, sec); X X X# X# tty usage report X# X printf("\n\n\nTTY\t\tConnect\t\t\%"); X printf("\tData\t\t\%\n"); X for(i in ttytime) { X X hours = ttytime[i] / 3600; X sec = ttytime[i] % 3600; X min = sec / 60; X sec %= 60; X X printf("%-10s\t%02d:%02d:%02d\t%3d\%\t%8d\t%3d\%\n", X i,hours,min,sec,ttytime[i]*100/tot_time, X ttyxfer[i],ttyxfer[i]*100/(tot_by_rec+tot_by_xmt)); X X } X} X SHAR_EOF $TOUCH -am 0219235491 uucp.awk && chmod 0664 uucp.awk || echo "restore of uucp.awk failed" set `wc -c uucp.awk`;Wc_c=$1 if test "$Wc_c" != "3168"; then echo original size 3168, current size $Wc_c fi # ============= uucp_daily ============== echo "x - extracting uucp_daily (Text)" sed 's/^X//' << 'SHAR_EOF' > uucp_daily && X: X# Mail the daily UUCP activity and append the file to the X# monthly log. X XSAGBIN=`cat /.SAGBIN` Xawk -f $SAGBIN/uucp.awk /usr/spool/uucp/.Admin/xferstats | \ X mail -s "Daily UUCP Activity" UUCP X Xset `date` XFile=$6$2 Xcd /usr/spool/uucp/.Admin Xcat xferstats >> $File SHAR_EOF $TOUCH -am 0220001491 uucp_daily && chmod 0775 uucp_daily || echo "restore of uucp_daily failed" set `wc -c uucp_daily`;Wc_c=$1 if test "$Wc_c" != "266"; then echo original size 266, current size $Wc_c fi # ============= uucp_traffic ============== echo "x - extracting uucp_traffic (Text)" sed 's/^X//' << 'SHAR_EOF' > uucp_traffic && X: X# Check the current day UUCP traffic by default or X# the traffic from a named file. X XSAGBIN=`cat /.SAGBIN` XFile=/usr/spool/uucp/.Admin/xferstats Xif [ $# -gt 0 ] Xthen X File=/usr/spool/uucp/.Admin/$* Xfi Xawk -f $SAGBIN/uucp.awk $File SHAR_EOF $TOUCH -am 0219235391 uucp_traffic && chmod 0775 uucp_traffic || echo "restore of uucp_traffic failed" set `wc -c uucp_traffic`;Wc_c=$1 if test "$Wc_c" != "233"; then echo original size 233, current size $Wc_c fi exit 0 -- Bill Irwin - The Westrheim Group - Vancouver, BC, Canada ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ uunet!van-bc!twg!bill (604) 431-9600 (voice) | Your Computer bill@twg.bc.ca (604) 430-4329 (fax) | Systems Partner