[net.news] Program for finding out what's subscribed to.

david@ukma.UUCP (David Herron, NPR Lover) (09/09/85)

#! /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 files:
:	'README'
:	'subscribers.6l'
:	'Makefile'
:	'subscribers.sh'
: This archive created: 'Mon Sep  9 13:36:50 1985
'
: By:	'David Herron, NPR Lover ()'
export PATH; PATH=/bin:$PATH
echo shar: extracting "'README'" '(1776 characters)'
if test -f 'README'
then
	echo shar: will not over-write existing file "'README'"
else
sed 's/^X//'  >'README' <<'SHAR_EOF'
XThis program was inspired by a program written by Fred Blonder and later
Xmodified heavily by Tim McCreery.  Here's Tim's README:
X
X> Many thanks to Fred Blonder who posted the shell script which
X> determines how many people are reading which newsgroups. I have
X> extended it to include consideration of the fa.* and mod.* newsgroups
X> as well. Also, I wanted to know who was reading some of these (more
X> esoteric) newsgroups, so I added the list of readers as well. Enjoy!
X> 					Tim McCreery
X> 					Normac Associates
X> 					(415) 947-0998
X> 					ihnp4!zehntel!normac!tim
X
XThis program does approximately the same thing, but is a little
Xmore intelligent about the data.  First thing it does is not even
XLOOK at old .newsrc files.  Second thing, it tosses .newsrc entries which
Xshow that the reader isn't up to date in the group. (This is detected
Xby looking at the last read article, if that is LESS THAN the least article
Xnumber in the group then s/he isn't up to date).  Third thing, its output
Xis a little more useful (for reading purposes), for each group it lists
Xthe number of readers, least and most article numbers, and the id's of
Xthe readers along with their last read article.  It also lists out
Xfor each reader the group s/he is reading.
X
XAnd, for all these, it keeps the output within 60-80 columns wide.
X
XThe program works by first concatenating all the data (active file,
Xreader's home directory, and their .newsrc file) and feeding that
Xto a large awk script.  Runtime is about 5 or 10 minutes on a -750
X(4.2 load average ~2, i.e. medium load) with a reader base of
Xabout 20 readers.
X
XIt probably could use some work because the output is rather large.
XAlso, it would be nice to have some kind of running average kept around.
X
X	David Herron
X	cbosgd!ukma!david
SHAR_EOF
if test 1776 -ne "`wc -c < 'README'`"
then
	echo shar: error transmitting "'README'" '(should have been 1776 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'subscribers.6l'" '(1293 characters)'
if test -f 'subscribers.6l'
then
	echo shar: will not over-write existing file "'subscribers.6l'"
else
sed 's/^X//'  >'subscribers.6l' <<'SHAR_EOF'
X.TH SUBSCRIBERS 6L "6-Sep-85" "U.K. Mathematical Sciences" 
X.SH NAME
Xsubscribers \- list how many people subscribe to each newsgroup
X.SH SYNOPSIS
X.I subscribers
X.SH DESCRIPTION
X.I Subscribers
Xis a short shell script which looks into everyone's
X$HOME/.newsrc file, to find out how many people subscribe to each newsgroup.
XThe resulting list is written to the standard output as two series\' of lines of
Xthe form:
X.sp
X.in +4
X# of readers <number>, # of groups <number>
X.br
X.sp
X<newsgroupname> # readers <number-of-subscribers>, articles [<first>..<last>]
X.br
X    <names>,<last-read-article> ...
X.br
X.sp
X<user-name>   <group>,<last-read-article> ...
X.in -4
X.sp
X.SH AUTHOR
XFred Blonder <fred@umcp-cs> originator.
X.br
X.sp
XTim McCreery <ucbvax!unisoft!normac!tim> added mod.* and fa.* to considerations
XAlso added list of subscribers to output.
X.br
X.sp
XDavid Herron <cbosgd!ukma!david> cleaned up some things and fixed it to
Xnot look at old .newsrc files.
X.SH FILES
X$HOME/.newsrc \- to find each individual user's subscription list
X.SH "SEE ALSO"
Xreadnews(1), news(5)
X.SH DIAGNOSTICS
XNone.
X.SH BUGS
XMay find bad .newsrc files as it simply uses find(1) to find them,
Xrather than looking in the password file for home directories.
XLast path name in the home directory is used for the subscriber name.
SHAR_EOF
if test 1293 -ne "`wc -c < 'subscribers.6l'`"
then
	echo shar: error transmitting "'subscribers.6l'" '(should have been 1293 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'Makefile'" '(280 characters)'
if test -f 'Makefile'
then
	echo shar: will not over-write existing file "'Makefile'"
else
sed 's/^X//'  >'Makefile' <<'SHAR_EOF'
Xinstall: subscribers
X	install -m 755 -o news -g news subscribers /usr/lib/news
X
Xsubscribers: subscribers.sh
X	cp subscribers.sh subscribers
X	chmod 755 subscribers
X
Xbundle: Makefile README subscribers.sh subscribers.6l
X	shar -a README subscribers.6l Makefile subscribers.sh >bundle
SHAR_EOF
if test 280 -ne "`wc -c < 'Makefile'`"
then
	echo shar: error transmitting "'Makefile'" '(should have been 280 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'subscribers.sh'" '(4813 characters)'
if test -f 'subscribers.sh'
then
	echo shar: will not over-write existing file "'subscribers.sh'"
else
sed 's/^X//'  >'subscribers.sh' <<'SHAR_EOF'
X#! /bin/sh
X#
X# @(#)subscribers.sh	(University of Maryland) Fred Blonder 19-Aug-1983
X#
X# Find out how many people subscribe to each newsgroup
X#
X# 16-Feb-85 T. Mc Creery - Add consideration of fa.* and mod.*.
X#		List login names of people who subscribe after newsgroup
X#
X# 9-Sep-1985 David Herron (ukma!david) --
X#	1. Make it not look at very old .newsrc's
X#	2. Made it very abusive to the system, as it exec's an awk
X#	   for every person that has a 'current' .newsrc.
X#	3. Gives various indicators about how much people are reading.
X
X`date`
X
Xbase_dir=/usr/user
Xfilefile=/tmp/#s.$$
Xdatafile=/tmp/#s2.$$
Xmakereport=/tmp/#s.1awk$$
Xselectgroups=/tmp/#s.2awk$$
Xsedfile=/tmp/#s.sed$$
Xreport=/usr/lib/news/DATA/users.$2.$3.$6
X
Xexport sedfile
X
Xtrap "rm -f $filefile $datafile $makereport $selectgroups $sedfile" 0 1 2 15
X
Xcat >$makereport <<'EOF'
X# subscribers.awk -- utility for subscribers.sh.  scans through data
X# file created to actually generate the report.
X#
X# Input file consists of records as follows:
X#
X# NF == 1	from "echo $dir".  Marker for beginning of new .newsrc
X# NF == 2	from "cat $dir/.newsrc".  One line of the newsrc.
X# NF == 4	from "cat /usr/lib/news/active"
X#
X# The input file is created a little below here in the shell file.
X#
X# Variable usage:
X#
X# grpnumber["newsgroup"] = <number>
X#	"hash" value for the newsgroup.  Used to speed access into a group
X#	of parallel arrays.
X#
X# grpname[<number>] = "newsgroup"
X#	The name of the group corresponding to <number>.
X#
X# grpcounts[<number>] = <number>
X#	The number of people reading the group.
X#
X# grpfirst[<number>] = <number>
X#	First article number in the group.
X#
X# grplast[<number>] = <number>
X#	Last article number in the group.
X#
X# grpreaders[<number>] = "readername,lastart" ...
X#	Sequence of <name,lastart> records for this group.  This could
X#	be parsed using a sequence of two split()'s (and a search
X#	between the split()'s).  Would rather have two dimensioned array...
X#
X# grpcount
X#	Last free hash value.  Also, number of groups seen already.
X#
X# rdrnumber["name"] = <number>
X#	Number corresponding to name.
X#
X# rdrname[<number>] = "name"
X#	Name corresponding to number.
X#
X# rdrgrps[<number>] = "groupname,lastart" ...
X#	Records of which groups the reader reads, and how well caught
X#	up he is.
X#
X# rdrcount
X#	Last free hash value.  Also, number of people seen already.
X#
X
XBEGIN	{ 
X	rdrcount = 0 
X	reader = "" 
X	grpcount = 0
X	}
X
XNF == 4	{
X	#	printf("%d: NF == %d <", NR, NF)
X	#	for (i=1; i < NF; i++)
X	#		printf("%s,", $i)
X	#	printf("%s>\n", $NF)
X	grpcount++
X	grpname[grpcount] = $1
X	grpnumber[$1] = grpcount
X	grplast[grpcount] = $2
X	grpfirst[grpcount] = $3
X	grpcounts[grpcount] = 0
X	grpreaders[grpcount] = ""
X	}
X
XNF == 1 {
X	#	printf("%d: NF == %d <", NR, NF)
X	#	for (i=1; i < NF; i++)
X	#		printf("%s,", $i)
X	#	printf("%s>\n", $NF)
X	nn = split($1, dirpath, "/")
X	reader = dirpath[nn]
X	rdrcount++
X	rdrname[rdrcount] = reader
X	rdrnumber[reader] = rdrcount
X	rdrgrps[rdrcount] = ""
X	}
X
XNF == 2 {
X	#	printf("%d: NF == %d <", NR, NF)
X	#	for (i=1; i < NF; i++)
X	#		printf("%s,", $i)
X	#	printf("%s>\n", $NF)
X	gnum = grpnumber[$1]
X	n1 = split($2, n2, "-")
X	n3 = split(n2[n1], n4, ",")
X	lastread = n4[n3]
X	if (lastread >= grpfirst[gnum]) {
X		grpcounts[gnum]++
X		grpreaders[gnum] = (grpreaders[gnum] " " reader "," lastread)
X		rdrgrps[rdrcount] = (rdrgrps[rdrcount] " " $1 "," lastread)
X	}
X	} 
X
X
XEND	{
X	printf("# readers %d, # groups %d\n", rdrcount, grpcount)
X	for (i=0; i < grpcount; i++) {
X	    if (grpcounts[i] > 0) {
X		printf("%s\t#readers: %d, articles [%d..%d]\n", \
X			grpname[i], grpcounts[i], grpfirst[i], grplast[i])
X		printf("\t")
X		nf = split(grpreaders[i], rdrs, " ")
X		width = 0
X		for (j=1; j <= nf; j++) {
X			width = width + length(rdrs[j])
X			if (width > 50) {
X				printf("\n\t")
X				width = 0
X			}
X			printf("%s ", rdrs[j])
X		}
X		printf("\n\n")
X	    }
X	}
X	for (i=0; i < rdrcount; i++) {
X		printf("%s\t", rdrname[i], rdrgrps[i])
X		width = 0
X		nf = split(rdrgrps[i], rdrs, " ")
X		for (j=1; j <= nf; j++) {
X			width = width + length(rdrs[j])
X			if (width > 50) {
X				printf("\n\t")
X				width = 0
X			}
X			printf("%s ", rdrs[j])
X		}
X		printf("\n\n")
X	}
X	}
X
XEOF
X
Xcat >$sedfile <<'EOF'
Xs/\/[^\/]*$//
Xs/^.*$/echo &; awk -f $selectgroups &\/.newsrc/
XEOF
X
Xcat >$selectgroups <<'EOF'
X# selectgroups.awk -- select which groups of the data file to actually use
X#
X# We're only interested in fa.all, net.all and mod.all data
X
X/^fa\..*: *[0-9].*$/	{ nn=split($0,n,":"); print n[1], n[2] }
X/^net\..*: *[0-9].*$/	{ nn=split($0,n,":"); print n[1], n[2] }
X/^mod\..*: *[0-9].*$/	{ nn=split($0,n,":"); print n[1], n[2] }
XEOF
X
X
X# find $base_dir -mtime -14 -name .newsrc -print >$filefile
X
X
X# do "echo $dir; cat $dir/.newsrc"
X# ( echo "cat /usr/lib/news/active"; sed -f $sedfile <$filefile) | tee aaa | sh >$datafile
Xawk -f $makereport < $datafile >$report
SHAR_EOF
if test 4813 -ne "`wc -c < 'subscribers.sh'`"
then
	echo shar: error transmitting "'subscribers.sh'" '(should have been 4813 characters)'
fi
fi # end of overwriting check
:	End of shell archive
exit 0