1*48648Sbostic#! /bin/sh 2*48648Sbostic: '/********************************************************************* 3*48648Sbostic uuusage 4*48648Sbostic Print summary of UUCP usage 5*48648Sbostic Alan S. Watt 6*48648Sbostic 7*48648Sbostic Sccsid=@(#)uuusage.sh 1.1 8*48648Sbostic 9*48648Sbostic usage: 10*48648Sbostic uuusage [-s] [-t] [period] 11*48648Sbostic 12*48648Sbostic arguments: 13*48648Sbostic -s Just produce the system summary; dont include 14*48648Sbostic individual user statistics. 15*48648Sbostic 16*48648Sbostic -t Produce tbl(1) output. 17*48648Sbostic 18*48648Sbostic period One of: 19*48648Sbostic today Just print todays activities 20*48648Sbostic week Week to date totals 21*48648Sbostic month Month to date totals 22*48648Sbostic m_name Totals for month <m_name> which 23*48648Sbostic is a three letter abbreviation 24*48648Sbostic for the month name. 25*48648Sbostic 26*48648Sbostic history: 27*48648Sbostic 02/28/83 original version 28*48648Sbostic *********************************************************************/' 29*48648Sbostic 30*48648Sbostic: 'format of SYSLOG is:' 31*48648Sbostic: 'cox onyxasw (4/16-18:24) received data 98 bytes 1 secs' 32*48648Sbostic: 'format for newer version of UUCP stuff is:' 33*48648Sbostic: 'swatt decvax (12/30-21:15) (378612944) sent data 64 bytes 0 secs' 34*48648Sbostic: 'array usage:' 35*48648Sbostic: ' files[name] == total number of files transferred' 36*48648Sbostic: ' bytes[name] == total number of bytes sent' 37*48648Sbostic: ' time[name] == total time spent by user' 38*48648Sbostic: ' totfiles,tottime,totbytes are like above, but totals' 39*48648Sbostic: ' sfiles[sname] == files transferred at request of system sname' 40*48648Sbostic: ' sbytes[sname] == bytes sent/received at request of sname' 41*48648Sbostic: ' stime[sname] == time spent at request of sname' 42*48648Sbostic 43*48648Sbosticlibdir=/usr/lib/uucp 44*48648Sbosticuudir=/usr/spool/uucp 45*48648Sbosticuutbl=$libdir/uutbl 46*48648Sbosticslogprefix="$uudir/OLD/SYSLOG" 47*48648Sbosticologprefix="$uudir/OLD/UUUSAGE" 48*48648Sbosticmonth= 49*48648Sbostictbloutput=0 50*48648Sbosticsystmonly=0 51*48648Sbosticfor arg 52*48648Sbosticdo 53*48648Sbostic case $arg in 54*48648Sbostic -s) : 'Only print system usage' 55*48648Sbostic systmonly=1 56*48648Sbostic ;; 57*48648Sbostic -t) : 'Generate TBL commands' 58*48648Sbostic tbloutput=1 ; systmonly=1 59*48648Sbostic ;; 60*48648Sbostic today) files="$uudir/SYSLOG" 61*48648Sbostic ;; 62*48648Sbostic week) files="$slogprefix.week $uudir/SYSLOG" 63*48648Sbostic ;; 64*48648Sbostic month) files="$slogprefix.month $slogprefix.week $uudir/SYSLOG" 65*48648Sbostic ;; 66*48648Sbostic [Jj]an) month=Jan 67*48648Sbostic ;; 68*48648Sbostic [Ff]eb) month=Feb 69*48648Sbostic ;; 70*48648Sbostic [Mm]ar) month=Mar 71*48648Sbostic ;; 72*48648Sbostic [Aa]pr) month=Apr 73*48648Sbostic ;; 74*48648Sbostic [Mm]ay) month=May 75*48648Sbostic ;; 76*48648Sbostic [Jj]un) month=Jun 77*48648Sbostic ;; 78*48648Sbostic [Jj]ul) month=Jul 79*48648Sbostic ;; 80*48648Sbostic [Aa]ug) month=Aug 81*48648Sbostic ;; 82*48648Sbostic [Ss]ep) month=Sep 83*48648Sbostic ;; 84*48648Sbostic [Oo]ct) month=Oct 85*48648Sbostic ;; 86*48648Sbostic [Nn]ov) month=Nov 87*48648Sbostic ;; 88*48648Sbostic [Dd]ec) month=Dec 89*48648Sbostic ;; 90*48648Sbostic *) files="$files $arg" 91*48648Sbostic ;; 92*48648Sbostic esac 93*48648Sbosticdone 94*48648Sbostic 95*48648Sbostic: 'look for short cut on monthly summaries. If we have one, 96*48648Sbostic just dump the summary, deleting the user information part if 97*48648Sbostic -s set; running output through $utbl if -t set. 98*48648Sbostic ' 99*48648Sbosticcase $month in 100*48648Sbostic'') ;; 101*48648Sbostic*) \ 102*48648Sbostic if [ -s ${ologprefix}.${month} ] 103*48648Sbostic then 104*48648Sbostic case $systmonly$tbloutput in 105*48648Sbostic "00") grep -v "uuusage: mangled record" \ 106*48648Sbostic ${ologprefix}.${month} 107*48648Sbostic ;; 108*48648Sbostic "10") grep -v "uuusage: mangled record" \ 109*48648Sbostic ${ologprefix}.${month} \ 110*48648Sbostic | sed -e '2,/^$/d' 111*48648Sbostic ;; 112*48648Sbostic "01"|"11") \ 113*48648Sbostic uuusage -s ${month} | $uutbl 114*48648Sbostic ;; 115*48648Sbostic esac 116*48648Sbostic exit 117*48648Sbostic else 118*48648Sbostic files=${slogprefix}.${month} 119*48648Sbostic fi ;; 120*48648Sbosticesac 121*48648Sbostic 122*48648Sbostic: 'Default report: today"s transfers' 123*48648Sbosticcase $files in 124*48648Sbostic '') files="$uudir/SYSLOG" 125*48648Sbostic ;; 126*48648Sbosticesac 127*48648Sbostic 128*48648Sbosticcase $tbloutput in 129*48648Sbostic 1) uuusage -s ${files} | $uutbl 130*48648Sbostic exit ;; 131*48648Sbosticesac 132*48648Sbostic 133*48648Sbosticflist= 134*48648Sbosticfor f in $files 135*48648Sbosticdo 136*48648Sbostic if [ -r $f ] 137*48648Sbostic then 138*48648Sbostic flist="$flist $f" 139*48648Sbostic else 140*48648Sbostic echo "$f: Cannot read file" 141*48648Sbostic fi 142*48648Sbosticdone 143*48648Sbostic 144*48648Sbosticset " " $flist ; shift 145*48648Sbosticcase $# in 146*48648Sbostic0) echo "no files to process" ; exit 1 ;; 147*48648Sbosticesac 148*48648Sbostic 149*48648Sbosticawk ' 150*48648SbosticBEGIN { 151*48648Sbostic systmonly='"$systmonly"' 152*48648Sbostic fmon = 1000; lmon = -1000 153*48648Sbostic oldnf = 9; newnf = 10 154*48648Sbostic # User Format: 155*48648Sbostic # user files bytes time Avgsiz Avgtim 156*48648Sbostic dfmt = "%-10s%6d%10d%8d%7d%7d\n" 157*48648Sbostic sfmt = "%-10s%6s%10s%8s%7s%7s\n" 158*48648Sbostic # System Format: 159*48648Sbostic # system files bytes time Avgsiz Avgtim rate 160*48648Sbostic sfmt1 = "%-10s%6s%10s%8s%7s%7s%7s\n" 161*48648Sbostic dfmt1 = "%-10s%6d%10d%8d%7d%7d%7d\n" 162*48648Sbostic space = "" 163*48648Sbostic 164*48648Sbostic # width of output for centering purposes 165*48648Sbostic width = 52 166*48648Sbostic} 167*48648Sbostic(NR == 1) { 168*48648Sbostic 169*48648Sbostic # Protect against partial records 170*48648Sbostic maxfields = NF 171*48648Sbostic if (NF == oldnf) 172*48648Sbostic oldfmt++ 173*48648Sbostic else if (NF == newnf) 174*48648Sbostic newfmt++ 175*48648Sbostic else { 176*48648Sbostic # cant seem to get awk to really exit here 177*48648Sbostic # it still tries to produce the report 178*48648Sbostic printf "uuusage: mangled format of 1st record\n" 179*48648Sbostic printf "must be either %d or %d fields\n", oldnf, newnf 180*48648Sbostic exit (1) 181*48648Sbostic } 182*48648Sbostic} 183*48648Sbostic(NF != maxfields) { 184*48648Sbostic printf "uuusage: mangled record #%d in file %s (ignored)\n", \ 185*48648Sbostic NR, FILENAME 186*48648Sbostic} 187*48648Sbostic(NF == maxfields) { 188*48648Sbostic 189*48648Sbostic # protect against format changes 190*48648Sbostic D_name = $1 191*48648Sbostic D_sname = $2 192*48648Sbostic D_date = $3 193*48648Sbostic 194*48648Sbostic # Old (V7/32V format vs. system III format) 195*48648Sbostic if (oldfmt) { 196*48648Sbostic D_bytes = $6 197*48648Sbostic D_time = $8 198*48648Sbostic } 199*48648Sbostic else if (newfmt) { 200*48648Sbostic D_bytes = $7 201*48648Sbostic D_time = $9 202*48648Sbostic } 203*48648Sbostic 204*48648Sbostic # protect against division by 0 205*48648Sbostic if (D_time == 0) 206*48648Sbostic D_time = 1 207*48648Sbostic 208*48648Sbostic # stash user usage info 209*48648Sbostic if (!systmonly) { 210*48648Sbostic name[D_name] = D_name; bytes[D_name] += D_bytes 211*48648Sbostic time[D_name] += D_time; files[D_name] += 1 212*48648Sbostic } 213*48648Sbostic 214*48648Sbostic # stash system usage info 215*48648Sbostic sname[D_sname] = D_sname; sbytes[D_sname] += D_bytes 216*48648Sbostic stime[D_sname] += D_time 217*48648Sbostic sfiles[D_sname] += 1 218*48648Sbostic 219*48648Sbostic # get the date of the transfer 220*48648Sbostic n = index (D_date, "/") 221*48648Sbostic cmon = substr (D_date, 2, n-2) 222*48648Sbostic m = index (D_date, "-") 223*48648Sbostic n++ 224*48648Sbostic cday = substr (D_date, n, m-n) 225*48648Sbostic 226*48648Sbostic 227*48648Sbostic # keep earliest and latest dates (naive about new year) 228*48648Sbostic if (int(cmon) < int(fmon) || (cmon == fmon && int(cday) < int(fday))) { 229*48648Sbostic fmon = cmon 230*48648Sbostic fday = cday 231*48648Sbostic } 232*48648Sbostic if (int(cmon) > int(lmon) || (cmon == lmon && int(cday) > int(lday))) { 233*48648Sbostic lmon = cmon 234*48648Sbostic lday = cday 235*48648Sbostic } 236*48648Sbostic} 237*48648SbosticEND { 238*48648Sbostic banner = sprintf "UUCP Usage from %s/%s to %s/%s", \ 239*48648Sbostic fmon,fday,lmon,lday 240*48648Sbostic precision = (width-length(banner))/2 241*48648Sbostic format = sprintf "%%%ds\n", precision + length(banner) 242*48648Sbostic printf format, banner 243*48648Sbostic if (!systmonly) { 244*48648Sbostic printf sfmt, "user", "files", "bytes", "time", \ 245*48648Sbostic "Avgsiz", "Avgtim" 246*48648Sbostic totfiles=0; totbytes=0; tottime=0 247*48648Sbostic for (n in name) { 248*48648Sbostic printf dfmt, n, files[n], bytes[n], time[n], \ 249*48648Sbostic bytes[n]/files[n], time[n]/files[n] 250*48648Sbostic totfiles += files[n] 251*48648Sbostic totbytes += bytes[n] 252*48648Sbostic tottime += time[n] 253*48648Sbostic } 254*48648Sbostic printf dfmt, "total", totfiles, totbytes, tottime, \ 255*48648Sbostic totbytes/totfiles, tottime/totfiles 256*48648Sbostic print space 257*48648Sbostic } 258*48648Sbostic 259*48648Sbostic # now print system usage info 260*48648Sbostic printf sfmt1, "system", "files", "bytes", "time", \ 261*48648Sbostic "Avgsiz", "Avgtim", "rate" 262*48648Sbostic totfiles=0; totbytes=0; tottime=0 263*48648Sbostic for (n in sname) { 264*48648Sbostic printf dfmt1, n, sfiles[n], sbytes[n], stime[n], \ 265*48648Sbostic sbytes[n]/sfiles[n], stime[n]/sfiles[n], \ 266*48648Sbostic sbytes[n]/stime[n] 267*48648Sbostic totfiles += sfiles[n] 268*48648Sbostic totbytes += sbytes[n] 269*48648Sbostic tottime += stime[n] 270*48648Sbostic } 271*48648Sbostic printf dfmt1, "total", totfiles, totbytes, tottime, \ 272*48648Sbostic totbytes/totfiles, tottime/totfiles, totbytes/tottime 273*48648Sbostic} ' $flist 274