1*311d040cSbostic#!/bin/sh
2*311d040cSbosticPATH=:/bin:/usr/bin:/usr/ucb
3*311d040cSbosticexport PATH
4*311d040cSbosticrm -f /tmp/cmds /tmp/callsto /tmp/callsfrom /tmp/inuse /tmp/outuse
5*311d040cSbostictouch /tmp/cmds /tmp/inuse /tmp/outuse
6*311d040cSbosticcd /usr/spool/uucp
7*311d040cSbosticif [ $# -gt 0 ]
8*311d040cSbosticthen
9*311d040cSbostic	what="$1/uucico/* $1/uux*/* $1/xferstats/*"
10*311d040cSbosticelse
11*311d040cSbostic	if [ -f LOGFILE ]
12*311d040cSbostic	then
13*311d040cSbostic		what="LOGFILE SYSLOG"
14*311d040cSbostic	else
15*311d040cSbostic		what="LOG/uucico/* LOG/uux*/* LOG/xferstats/*"
16*311d040cSbostic	fi
17*311d040cSbosticfi
18*311d040cSbosticsed -e "s/PATH=.*PATH;//
19*311d040cSbostic/REQUEST/d"  $what |
20*311d040cSbostic/bin/awk '
21*311d040cSbosticBEGIN { fmon = fday = ftime = 99
22*311d040cSbostic	lmon = lday = ltime = 0 }
23*311d040cSbostic$4 ~ /SUCCEEDED|OK/ {
24*311d040cSbostic	t = substr($3,index($3,"-")+1,5)
25*311d040cSbostic	split(t,time,":")
26*311d040cSbostic	if($5 !~ /conversation/) {
27*311d040cSbostic		startup[$2] = time[1]*60+time[2]
28*311d040cSbostic		date[$2] = substr($3, 2, index($3,"-")-2)
29*311d040cSbostic	}
30*311d040cSbostic}
31*311d040cSbostic$4 ~ /FAILED|CAUGHT|OK|TIMEOUT/ {
32*311d040cSbostic	if(startup[$2] == 0 || $5 ~ /startup/)
33*311d040cSbostic		continue
34*311d040cSbostic	t = substr($3,index($3,"-")+1,5)
35*311d040cSbostic	split(t,time,":")
36*311d040cSbostic	elapsed = time[1]*60+time[2] - startup[$2]
37*311d040cSbostic	if (elapsed < 0 )
38*311d040cSbostic		elapsed += 24*60
39*311d040cSbostic	if (elapsed == 0)
40*311d040cSbostic		elapsed = 1
41*311d040cSbostic	if(callto[$2] ){
42*311d040cSbostic		totcallto[$2] += elapsed
43*311d040cSbostic		numcallto[$2]++
44*311d040cSbostic		printf("%s\t%s\t%02d:%02d - %02d:%02d\n",$2,date[$2],startup[$2]/60,startup[$2]%60,time[1],time[2])>>"/tmp/callsto"
45*311d040cSbostic	}else{
46*311d040cSbostic		totcallby[$2] += elapsed
47*311d040cSbostic		numcallby[$2]++
48*311d040cSbostic		printf("%s\t%s\t%02d:%02d - %02d:%02d\n",$2,date[$2],startup[$2]/60,startup[$2]%60,time[1],time[2])>>"/tmp/callsfrom"
49*311d040cSbostic	}
50*311d040cSbostic	callto[$2] = 0
51*311d040cSbostic	startup[$2] = 0
52*311d040cSbostic}
53*311d040cSbostic$4 ~ /SUCCEEDED/{
54*311d040cSbostic	if ($5 ~ /call/)
55*311d040cSbostic		callto[$2]++
56*311d040cSbostic}
57*311d040cSbostic$4 ~ /FAILED|CAUGHT/{
58*311d040cSbostic	if ($5 ~ /call|conversation|SIGNAL/ )
59*311d040cSbostic		failed[$2]++
60*311d040cSbostic}
61*311d040cSbostic$5 ~ /sent/{
62*311d040cSbostic	sentbytes[$2] += $7
63*311d040cSbostic	sentfiles[$2] ++
64*311d040cSbostic	seconds[$2] += $9
65*311d040cSbostic	retries[$2] += $11
66*311d040cSbostic	havout = 1
67*311d040cSbostic	outuse[$1] = $1
68*311d040cSbostic	outusebytes[$1] += $7
69*311d040cSbostic	outusefiles[$1] ++
70*311d040cSbostic	outusesecs[$1] += $9
71*311d040cSbostic}
72*311d040cSbostic$5 ~ /received/{
73*311d040cSbostic	recbytes[$2] += $7
74*311d040cSbostic	recfiles[$2] ++
75*311d040cSbostic	seconds[$2] += $9
76*311d040cSbostic	retries[$2] += $11
77*311d040cSbostic	havin = 1
78*311d040cSbostic	inuse[$2 "!" $1] = $2 "!" $1
79*311d040cSbostic	inusebytes[$2 "!" $1] += $7
80*311d040cSbostic	inusefiles[$2 "!" $1] ++
81*311d040cSbostic	inusesecs[$2 "!" $1] += $9
82*311d040cSbostic}
83*311d040cSbostic$5 ~/XQT/{
84*311d040cSbostic	if( $7 ~ /!|@/ && $6 ~ /rmail/)
85*311d040cSbostic		printf("%s\t%s\t%-8s\t%s\n",substr($3,2,index($3,"-")-2),substr($3,index($3,"-")+1,5),$2 "!" $4,$7)>>"/tmp/cmds"
86*311d040cSbostic}
87*311d040cSbostic$4 ~/XQT/{
88*311d040cSbostic	if ($1 ~ /uucp|daemon|root|news/ || $7 != "rmail")
89*311d040cSbostic		continue
90*311d040cSbostic	printf("%s\t%s\t%-8s\t%s!%s\n",substr($3,2,index($3,"-")-2),substr($3,index($3,"-")+1,5),$1,$2,$7)>>"/tmp/cmds"
91*311d040cSbostic}
92*311d040cSbostic$10 ~/secs/ {
93*311d040cSbostic	curtime = substr($4, 5, 6)
94*311d040cSbostic	dtmp = curtime - int($9) - lasttime[$2]
95*311d040cSbostic	if (dtmp > 0 && dtmp < 20)
96*311d040cSbostic		dead[$2] += dtmp
97*311d040cSbostic	lasttime[$2] = curtime
98*311d040cSbostic	live[$2] += $9
99*311d040cSbostic}
100*311d040cSbostic{
101*311d040cSbostic	n = index ($3, "/")
102*311d040cSbostic	thismon = 0
103*311d040cSbostic	if (n > 0 ) {
104*311d040cSbostic		thismon = int(substr($3, 2, n-2))
105*311d040cSbostic		if (lmon < thismon)
106*311d040cSbostic			lmon = thismon
107*311d040cSbostic		if (thismon < fmon)
108*311d040cSbostic			fmon = thismon
109*311d040cSbostic	}
110*311d040cSbostic	m = index ($3, "-")
111*311d040cSbostic	n++
112*311d040cSbostic	thisday = 0
113*311d040cSbostic	if( (m-n) > 0 ) {
114*311d040cSbostic		thisday = int(substr($3, n, m-n))
115*311d040cSbostic		if ((lday < thisday) && (lmon == thismon) || ldaymon != lmon) {
116*311d040cSbostic			lday = thisday
117*311d040cSbostic			ldaymon = thismon
118*311d040cSbostic		}
119*311d040cSbostic		if ((thisday < fday) && (fmon == thismon) || fdaymon != fmon) {
120*311d040cSbostic			fday = thisday
121*311d040cSbostic			fdaymon = thismon
122*311d040cSbostic		}
123*311d040cSbostic	}
124*311d040cSbostic	thistime = substr($3,m+1,5)
125*311d040cSbostic	if ((ltime < thistime) && (lmon == thismon) && (lday == thisday))
126*311d040cSbostic		ltime = thistime
127*311d040cSbostic	if ((thistime < ftime) && (fmon == thismon) && (fday == thisday))
128*311d040cSbostic		ftime = thistime
129*311d040cSbostic}
130*311d040cSbosticEND{
131*311d040cSbostic	printf("\n\t\t\t\tUUCP Traffic Summary\n\n")
132*311d040cSbostic	printf("\t\t\t\tFrom %d/%d %s To %d/%d %s\n\n",fmon,fday,ftime,lmon,lday,ltime)
133*311d040cSbostic	printf("\t      Calls    Minutes     Files       Bytes      Effective   Unused\n")
134*311d040cSbostic	printf("Site[Failed] To/From   To/From    To/From   Sent/Received  Baudrate  Bandwidth\n")
135*311d040cSbostic	for( i in startup ){
136*311d040cSbostic		if(seconds[i]== 0)seconds[i]++
137*311d040cSbostic		if(dead[i]+live[i])
138*311d040cSbostic			percent = dead[i]*100/(dead[i]+live[i])
139*311d040cSbostic		else
140*311d040cSbostic			percent = 0
141*311d040cSbostic		if (failed[i] || retries[i]) {
142*311d040cSbostic			temp = i "[" failed[i]
143*311d040cSbostic			if (retries[i])
144*311d040cSbostic				temp = temp "/" retries[i] "]"
145*311d040cSbostic			else
146*311d040cSbostic				temp = temp "]"
147*311d040cSbostic		} else
148*311d040cSbostic			temp = i
149*311d040cSbostic		printf("%-12s %3d/%-3d %5d/%-5d %4d/%-4d %8d/%-8d %6d  %5d%%\n",\
150*311d040cSbostic		temp,numcallto[i],numcallby[i],\
151*311d040cSbostic		totcallto[i],totcallby[i],\
152*311d040cSbostic		sentfiles[i],recfiles[i],\
153*311d040cSbostic		sentbytes[i],recbytes[i],\
154*311d040cSbostic		(recbytes[i]+sentbytes[i])*8/seconds[i],\
155*311d040cSbostic		percent)
156*311d040cSbostic	}
157*311d040cSbostic	printf("\n\n\n\t\t\t\tOriginating Users\n\n")
158*311d040cSbostic	printf("User\t\t       Minutes     Files       Bytes\n\n")
159*311d040cSbostic	if (havout == 1) {
160*311d040cSbostic		for (i in outuse) {
161*311d040cSbostic			printf("%-21s %5d    %7d      %8d\n", i,\
162*311d040cSbostic				(outusesecs[i]+30)/60,\
163*311d040cSbostic				outusefiles[i], outusebytes[i]) >> "/tmp/outuse"
164*311d040cSbostic		}
165*311d040cSbostic	}
166*311d040cSbostic	if (havin == 1) {
167*311d040cSbostic		for (i in inuse) {
168*311d040cSbostic			printf("%-21s %5d    %7d      %8d\n", i,\
169*311d040cSbostic				(inusesecs[i]+30)/60,\
170*311d040cSbostic				inusefiles[i], inusebytes[i]) >> "/tmp/inuse"
171*311d040cSbostic		}
172*311d040cSbostic	}
173*311d040cSbostic}'
174*311d040cSbostic
175*311d040cSbosticsort /tmp/outuse
176*311d040cSbosticecho " "
177*311d040cSbosticsort /tmp/inuse
178*311d040cSbosticecho " "
179*311d040cSbosticecho " "
180*311d040cSbosticecho " "
181*311d040cSbosticecho "		Long Distance Calls"
182*311d040cSbosticecho
183*311d040cSbosticecho "To	Day	Start - End	    From    Day     Start - End"
184*311d040cSbosticcat >/tmp/$$local<<!!!
185*311d040cSbostic/^ut/d
186*311d040cSbostic!!!
187*311d040cSbosticsed -f /tmp/$$local /tmp/callsto | /bin/awk '
188*311d040cSbostic{
189*311d040cSbostic	if (last == $1)
190*311d040cSbostic		pr = ""
191*311d040cSbostic	else {
192*311d040cSbostic		last = $1
193*311d040cSbostic		pr = $1
194*311d040cSbostic	}
195*311d040cSbostic	if (pr == "" && date == $2)
196*311d040cSbostic		pd = ""
197*311d040cSbostic	else {
198*311d040cSbostic		date = $2
199*311d040cSbostic		pd = $2
200*311d040cSbostic	}
201*311d040cSbostic	printf("%s\t%s\t%s - %s\n",pr,pd,$3,$5)
202*311d040cSbostic}'>/tmp/$$a
203*311d040cSbosticsed -f /tmp/$$local /tmp/callsfrom | /bin/awk '
204*311d040cSbostic{
205*311d040cSbostic	if (last == $1)
206*311d040cSbostic		pr = ""
207*311d040cSbostic	else {
208*311d040cSbostic		last = $1
209*311d040cSbostic		pr = $1
210*311d040cSbostic	}
211*311d040cSbostic	if (pr == "" && date == $2)
212*311d040cSbostic		pd = ""
213*311d040cSbostic	else {
214*311d040cSbostic		date = $2
215*311d040cSbostic		pd = $2
216*311d040cSbostic	}
217*311d040cSbostic	printf("%s\t%s\t%s - %s\n",pr,pd,$3,$5)
218*311d040cSbostic}'>/tmp/$$b
219*311d040cSbosticpr -t -m /tmp/$$a /tmp/$$b | uniq
220*311d040cSbosticrm -f /tmp/$$[ab]
221*311d040cSbosticsed -e "
222*311d040cSbostic/rmail	seismo!/d
223*311d040cSbostic/rmail	rlgvax!/d
224*311d040cSbostic/rmail	rochester!/d
225*311d040cSbostic/rmail	umcp-cs!/d
226*311d040cSbostic/rmail	brl-tgr!/d
227*311d040cSbostic/rmail	brl-vgr!/d
228*311d040cSbostics/)$//
229*311d040cSbostic" /tmp/cmds >/tmp/$$c
230*311d040cSbosticif [ -s /tmp/$$c ]
231*311d040cSbosticthen
232*311d040cSbostic	echo " "
233*311d040cSbostic	echo " "
234*311d040cSbostic	echo " "
235*311d040cSbostic	echo "		Outgoing Mail from Other Sites"
236*311d040cSbostic	echo
237*311d040cSbostic	echo "Day	Time	From		To"
238*311d040cSbostic	cat /tmp/$$c
239*311d040cSbosticfi
240*311d040cSbosticrm -f /tmp/cmds /tmp/$$* /tmp/callsto /tmp/callsfrom /tmp/inuse /tmp/outuse
241