[net.sources] How to tell who is reading which newsgroups

tim@normac.UUCP (Tim McCreery) (02/20/85)

Many thanks to Fred Blonder who posted the shell script which
determines how many people are reading which newsgroups. I have
extended it to include consideration of the fa.* and mod.* newsgroups
as well. Also, I wanted to know who was reading some of these (more
esoteric) newsgroups, so I added the list of readers as well. Enjoy!
					Tim McCreery
					Normac Associates
					(415) 947-0998
					ihnp4!zehntel!normac!tim

# ------------------------- cut here -------------------------
# This is a shell archive.  Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file".  (Files
# unpacked will be owned by you and have default permissions.)
#
# -------- subscribers.6l --------
echo extracting file subscribers.6l
sed 's/^//' << '\E*O*F' > subscribers.6l
.TH SUBSCRIBERS 6L "18-Feb-85"
.SH NAME
subscribers \- list how many people subscribe to each newsgroup
.SH SYNOPSIS
.I subscribers
.SH DESCRIPTION
.I Subscribers
is a short shell script which looks into the password file, and everyone's
$HOME/.newsrc file, to find out how many people subscribe to each newsgroup.
The resulting list is written to the standard output as a series of lines of
the form:
.sp
.ti +4
newsgroupname number-of-subscribers names-of-subscribers
.sp
sorted by decreasing number of subscribers.
.SH AUTHOR
Fred Blonder <fred@umcp-cs> originator.
.br
Tim McCreery <ucbvax!unisoft!normac!tim> added mod.* and fa.* to considerations
Also added list of subscribers to output.
.SH FILES
.in +15
.ti -15
/etc/passwd \- to find all login directories.
.br
.ti -15
$HOME/.newsrc \- (for each entry in /etc/passwd) to find each individual
user's subscription list
.in -15
.SH "SEE ALSO"
readnews(1), news(5)
.SH DIAGNOSTICS
None.
.SH BUGS
Doesn't take into account multiple accounts using the same login directory,
or people who change their $HOME directory. Last path name in the
home directory is used for the subscriber name.
\E*O*F
# -------- subscribers.sh --------
echo extracting file subscribers.sh
sed 's/^//' << '\E*O*F' > subscribers.sh
#! /bin/sh
#
# @(#)subscribers.sh	(University of Maryland) Fred Blonder 19-Aug-1983
# 16-Feb-85 T. Mc Creery - Add consideration of fa.* and mod.*.
#		List login names of people who subscribe after newsgroup
#
# Find out how many people subscribe to each newsgroup

sub_tmp=/tmp/#s.$$

trap "rm -f $sub_tmp" 0 1 2 15

homedir=`awk -F: '{ print $6 }' /etc/passwd | sort -u`
for dir in $homedir
do	# locate all login directories
	if	# if .newsrc exists
		[ -r $dir/.newsrc ]
	then 	# find all newsgroups subscribed to, append to $sub_tmp
		echo $dir >> $sub_tmp
		awk -F: '/^fa\..*: [0-9].*$/ { print $1 }; \
			 /^net\..*: [0-9].*$/ { print $1 }; \
			 /^mod\..*: [0-9].*$/ { print $1 }' \
			$dir/.newsrc >> $sub_tmp
	fi
done

# Count all ocurrences of all newsgroups.
# Print result sorted by decreasing number of subscribers.
awk ' \
BEGIN { newsreaders = 0; } \
{ \
nn = split($1,dirpath,"/"); \
if (nn > 1) { \
	newsreaders++; \
	reader = dirpath[nn]; \
} else { \
	x[$1] = x[$1] + 1; \
	if (names[$1] == "") \
		names[$1] = reader; \
	else \
		names[$1] = (names[$1] "," reader); \
} \
} \
END { for (i in x) printf("%s %d %s\n",i,x[i],names[i]); \
      printf(" %d news readers\n",newsreaders); } \
' < $sub_tmp | sort +1 -rn 
\E*O*F
echo Done with extraction