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