artp@seismo.CSS.GOV@motbos.UUCP (08/11/87)
Motorola System 1131 System V Release 2 Version 3 (Bourne and Korn Shells) Motorola Delta System 2016 System V Release 3 Version 1 (Bourne Shell) Several processing options are available as well as an option for syntax (-h). A shell archive follows the sample display: ==================== start of sample display ================================ UUCP NETWORK TRANSACTION STATISTICS (NODE: motbos Thu Jul 9 13:59:05 EDT 1987) (Processing Transactions of: 7/8/87) NODE USER XACT BYTES TIME (Sec) RATE (Bytes/Sec) ______________________________________________________________________________ mcdbos artp 3 22396 26 861 mcdbos bin 2 9460 12 788 mcdbos lp 18 58943 71 830 mcdbos root 2 1103 2 551 mcdbos TOTAL: 25 91902 111 827 motatl usenet 10 266605 2461 108 motatl TOTAL: 10 266605 2461 108 motham artp 2 807 6 134 motham usenet 10 266605 2424 109 motham TOTAL: 12 267412 2430 110 motrhr usenet 2 54581 496 110 motrhr TOTAL: 2 54581 496 110 motsj1 usenet 8 168336 1564 107 motsj1 TOTAL: 8 168336 1564 107 wdc202 usenet 1 55871 508 109 wdc202 TOTAL: 1 55871 508 109 ______________________________________________________________________________ motbos TOTAL: 58 904707 7570 119 ========================= end of sample display ============================ Run the un-archive as root or bin user. ================================ cut here ================================= #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the file: # uucp.stat # This archive created: Thur July 9, 1987 @ 12:00 EDT export PATH; PATH=/bin:$PATH if test -f 'uucp.stat' then echo shar: will not over-write existing file "'uucp.stat'" else cat << \SHAR_EOF > 'uucp.stat' # uucp.stat: script to print the UUCP transaction statistics (aap 7/9/87) # for System V Release 2 or 3 formatted UUCP transaction files # Version 1.0 # # This program will process the uucp transactions for each node and report # total transaction statistics. Processing is performed on the file $UUCP_LOG # which defaults to: # /usr/spool/uucp/SYSLOG (Rlse 2) or /usr/spool/uucp/.Admin/xferstats (Rlse 3). # Processing defaults to statistics for the current day. Options allow # processing of all transactions found (usually the current week's # transactions are maintained) or a specific day's transactions. # Output is directed to standard output. # # INSTALLATION NOTES - # # uucp.stat is non-intrusive and should be installed with 755 permissions. # Set the variable: $RLSE_LVL to the System V major release level that # you are running prior to installation. # # syntax: uucp.stat [<option>] # # where <option> is one or more of the following: # # -a : process all transactions found # -u : do not display user statistics # -n : do not display node statistics # -t : do not display total statistics # mm/dd : process transactions for month/day. # (do not use leading zeroes) # -h : display syntax only # -v : display program parameters # # If no <option> is specified, process today's transactions only. # PROG_VERSION=1.0 # Program Version number RLSE_LVL=2 # major system V release level # PHASE 1 - INITIALIZATION, OPTION PARSING # processing for today's date. Note sed processing to remove leading 0's # since $UUCP_LOG file's date stamp does not use them MONTH=`date '+%m'|sed "s/^0//"` DAY=`date '+%d'|sed "s/^0//"` YEAR=`date '+%y'` # PRINT MODE FLAGS USER_DISPLAY=1 NODE_DISPLAY=1 GRAND_DISPLAY=1 PARAM_DISPLAY=0 LOCAL_NODE="`uuname -l`" # local node name # adjust transaction log file as a function of System V release level case $RLSE_LVL in 2) UUCP_LOG="/usr/spool/uucp/SYSLOG";; 3) UUCP_LOG="/usr/spool/uucp/.Admin/xferstats";; *) echo "$0: Release level parameter is invalid";exit ;; esac if [ -s $UUCP_LOG ] && [ -r $UUCP_LOG ] # if non-zero file and is readable then # default to processing of current day's statistics DATE=$MONTH/$DAY # determine any processing options from command line if [ $# != 0 ] then for OPT in $* do case $OPT in "?" | "-h") echo " syntax: $0 [<option>]" echo " where <option> is one or more of the following:" echo " -h : display syntax " echo " -a : process statistics for all days found " echo " -u : do not display user statistics" echo " -n : do not display node statistics" echo " -t : do not display total statistics" echo " mo/day : process statistics for specific month/day" echo " (do not use leading zeroes)" echo " -v : display program characteristics" echo " default is to process today's transactions only" exit ;; "-u" ) USER_DISPLAY=0 ;; "-n" ) NODE_DISPLAY=0 ;; "-t" ) GRAND_DISPLAY=0 ;; "-v" ) PARAM_DISPLAY=1 ;; "-a" ) DATE=0 ;; *) DATE="$OPT" ;; esac done fi # PRINT ROUTINES # Display Individual Login User Stats USER_STATS () { if [ $USER_DISPLAY != 0 ] then echo "$NODE\t$LOGIN\t$USER_XACT\t$USER_BYTES\t\t$USER_TIME\c" if [ $USER_TIME != 0 ] then echo "\t\t`expr $USER_BYTES / $USER_TIME`" else echo "\n" fi fi ;} # Display Node Statisitcs NODE_STATS () { if [ $NODE_DISPLAY != 0 ] then echo "$NODE\tTOTAL:\t$NODE_XACT\t$NODE_BYTES\t\t$NODE_TIME\c" if [ $NODE_TIME != 0 ] then echo "\t\t`expr $NODE_BYTES / $NODE_TIME`\n" else echo "\n" fi fi ;} # Display Grand Totals GRAND_TOTALS () { if [ $GRAND_DISPLAY != 0 ] then echo "_________________________________________________________\c" echo "_____________________\n" echo "$LOCAL_NODE\tTOTAL:\t$TOT_XACT\t$TOT_BYTES\t\t$TOT_TIME\c" if [ $TOT_TIME != 0 ] then echo "\t\t`expr $TOT_BYTES / $TOT_TIME`" else echo "\n" fi fi ;} # Print header PRINT_HEADER () { if [ $PARAM_DISPLAY = 1 ] then echo "[uucp.stat] Version: $PROG_VERSION O/S Rlse Level: $RLSE_LVL" echo "[uucp.stat] Transaction File: $UUCP_LOG" echo "[uucp.stat] Print Flags: User=$USER_DISPLAY Node:$NODE_DISPLAY\c" echo " Total:$GRAND_DISPLAY\n\n\n" fi echo "\t\tUUCP NETWORK TRANSACTION STATISTICS" echo "\t\t(NODE: $LOCAL_NODE `date`)\n" if [ $DATE != 0 ] then echo "\t\t(Processing Transactions of: $DATE/$YEAR)\n" else echo "\t\t(Processing All Transactions)\n" fi echo "NODE\tUSER\tXACT\tBYTES\t\tTIME (Sec)\tRATE (Bytes/Sec)" echo "_________________________________________________________\c" echo "_____________________\n" ;} # PHASE 2 - PRE-PROCESSING OF $UUCP_LOG FILE # by making one pass at the $UUCP_LOG file and extracting just the # fields for node & username, byte count and transaction time, # then sorting them by node and login, we can process the sub-totals # and totals synchronously and process more quickly then by mutiple passes. PRINT_HEADER EOF=0 # if a date option was specified then extract only the records for that date grep ! $UUCP_LOG | ( if [ $DATE != 0 ] then grep $DATE else cat fi) | # separate first field (node!login - replace ! by space) for separate arguments sed "s/\!/ /" | # process the $UUCP_LOG file key fields into a sorted data stream of records ( until [ $EOF != 0 ] do read NODE LOGIN A3 A4 A5 A6 A7 BUFFER if [ $? != 0 ] then EOF=1 else set $BUFFER BYTES=$1 TIME=$3 if [ $RLSE_LVL = 3 ] # Rlse 3 xaction log file has time as fractional number # which cannot be operated on by "expr" then R3_RATE=$5 TIME=`expr $BYTES / $R3_RATE ` fi echo "$NODE $LOGIN $BYTES $TIME" fi done ) | # now sort the stream in order of $NODE,$LOGIN,$BYTES,$TIME sort | # PHASE 3 - PROCESS EACH TRANSACTION RECORD AND CALCULATE/DISPLAY STATS ( NODE=0 LOGIN=0 EOF=0 TOT_XACT=0 TOT_BYTES=0 TOT_TIME=0 USER_XACT=0 USER_BYTES=0 USER_TIME=0 NODE_XACT=0 NODE_BYTES=0 NODE_TIME=0 until [ $EOF != 0 ] do read A1 A2 BYTES TIME if [ $? != 0 ] then # END-OF-FILE PROCESSING # print last node totals and grand totals EOF=1 if [ $NODE != 0 ] # some transaction records found then USER_STATS NODE_STATS GRAND_TOTALS # no transaction records found else echo "No Transactions Found For: $DATE" fi else # VALID TRANSACTION RECORD FOUND if [ $NODE = 0 ] || [ $NODE = $A1 ] then # first entry or same node as previous entry if [ $LOGIN = 0 ] || [ $LOGIN = $A2 ] then # first entry or same login as previous entry USER_XACT=`expr $USER_XACT + 1 ` USER_BYTES=`expr $USER_BYTES + $BYTES` USER_TIME=`expr $USER_TIME + $TIME` else # login is different than previous login. # print current user's summaries. USER_STATS # init counters for new login USER_XACT=1 USER_BYTES=$BYTES USER_TIME=$TIME fi # update node statistics NODE_XACT=`expr $NODE_XACT + 1 ` NODE_BYTES=`expr $NODE_BYTES + $BYTES` NODE_TIME=`expr $NODE_TIME + $TIME` NODE=$A1 LOGIN=$A2 else # Node name is different than previous entry # print previous user and node totals USER_STATS NODE_STATS # init counters for new node NODE=$A1 LOGIN=$A2 USER_XACT=1 USER_BYTES=$BYTES USER_TIME=$TIME NODE_XACT=1 NODE_BYTES=$BYTES NODE_TIME=$TIME fi # update grand totals TOT_XACT=`expr $TOT_XACT + 1 ` TOT_BYTES=`expr $TOT_BYTES + $BYTES` TOT_TIME=`expr $TOT_TIME + $TIME` fi done ) else # uucp transaction statistics file ($UUCP_LOG) is unaccessable or empty echo "$0: File: $UUCP_LOG unaccessable or empty" fi SHAR_EOF fi # end of overwriting check # End of shell archive exit 0 ========================================================================== Regards, Art -------------------------------- << Unusual Disclaimer >> "...Unix is my life, Howard..." Art Parmet - AEM @ Motorola Semiconductor, Woburn, Ma. UUCP: {hplabs!motsj1, mot!motsj1} {cdx39, motsj1, mottom, oakhill, mnetor, motatl, motdc1, motrhr, motsan, wdc202, mothup, motham, mcdchg, motcso, pixel}....motbos!artp Voice: +1 617-932-9700 UUCP: +1 617-932-9191 Fax: +1 617-932-9100