home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sources / d / 1507 < prev    next >
Encoding:
Internet Message Format  |  1993-01-01  |  9.1 KB

  1. Xref: sparky comp.sources.d:1507 news.admin:8781
  2. Path: sparky!uunet!haven.umd.edu!decuac!pa.dec.com!reid
  3. From: reid@decwrl.DEC.COM (Brian Reid)
  4. Newsgroups: comp.sources.d,news.admin
  5. Subject: arbitron program (v2.4.4--last updated 20 Oct 1989)
  6. Date: 1 Jan 1993 20:42:39 GMT
  7. Organization: DEC Network Systems Laboratory
  8. Lines: 252
  9. Message-ID: <1i2abvINN40q@usenet.pa.dec.com>
  10. NNTP-Posting-Host: torrey.pa.dec.com
  11. Keywords: arbitron, software
  12. Originator: reid@torrey.pa.dec.com
  13.  
  14. This is the script for the "arbitron" system that is used to produce the
  15. data for the monthly USENET readership surveys in news.lists. It is not so
  16. much a "source" as it is a piece of USENET folklore, posted every month so
  17. that new people will be sure to find it. (CF the "History of USENET" articles
  18. posted every month). It is posted to these newsgroups rather than to a source
  19. group so that it will be widely available but will not be archived.
  20.  
  21. #! /bin/sh
  22. # @(#)arbitron    2.4.4    10/20/89
  23. # arbitron -- this program produces rating sweeps for USENET.
  24. #
  25. # Usage: arbitron
  26. #
  27. # To use this program, edit the "configuration" section below so that the
  28. # information is correct for your site, and then run it. It will produce a
  29. # readership survey for your machine and mail that survey to decwrl.dec.com,
  30. # with a cc to you.
  31. #
  32. # To participate in the international monthly ratings sweeps, 
  33. # run "arbitron" every month. I will run the statistics program on the first
  34. # day of each month; it will include any report that has reached it by that
  35. # time. To make sure your site's data is included, run the survey program no
  36. # later than the 20th day of each month.
  37. #
  38. # Brian Reid, DEC Western Research Lab, reid@decwrl.dec.com
  39. # Updated and bugfixed by 
  40. #    Spencer Thomas, U.of Utah
  41. #    Geoff Kuenning, SAH Consulting
  42. # Updated to work with 2.10.1 and older news systems by
  43. #    Lindsay Cleveland, AT&T Technologies/Bell Labs
  44. # Made to work with 16-bit address spaces by
  45. #    Andy Walker, Maths Dept., University of Nottingham, UK
  46. # Nagging Bourne shell bug fixed by
  47. #    Tom Donahue, Rabbit Software Corp
  48. # Various suggestions provided by:
  49. #    Karl Tombre, CRIN, Vandoeuvre France
  50. #    Dan Kolkowitz, Stanford
  51. #    Paul Eggert, Unisys
  52. # Fixes for YP and NN by
  53. #    Dan Kolkowitz, Stanford
  54. #    Brent Chapman, Capital Market Technology
  55. #
  56. # Note that the results of this program are dependent on the rate at which
  57. # you expire news.  If you are a small site that expires news rapidly, the
  58. # results may indicate fewer active readers than you actually have.
  59. #
  60. ###########################################################################
  61. # Configuration information. Edit this section to reflect your site data. #
  62. TMPDIR=/tmp
  63. NEWS=/usr/lib/news
  64. SPOOL=/usr/spool/news
  65.  
  66. # Make a crude stab at determining the system type. If your installation has
  67. # only one type of system, you can edit out the "if" statement and just turn
  68. # this into an assignment statement of the correct value.
  69. if [ -d /usr/ucb ]
  70. then
  71.     STYPE="bsd"
  72. else
  73.     STYPE="usg"
  74. fi
  75.  
  76. # Range of /etc/passwd UID's that represent actual people (rather than
  77. # maintenance accounts or daemons or whatever)
  78. lowUID=5
  79. highUID=9999
  80.  
  81. # If you aren't running a distributed news system (nntpd & rrn, usually),
  82. # leave NEWSHOST blank. Else set it to the name of the host from which you
  83. # can rcp a copy of the active file.
  84. NEWSHOST=
  85.  
  86. # uucp path: {sun, hplabs, pyramid, decvax, ucbvax}!decwrl!netsurvey
  87. summarypath="netsurvey@decwrl.dec.com $USER"
  88.  
  89.  
  90. # We need to find the uucp name of your host. If this code doesn't work,
  91. # then just put it in literally like this:
  92. #    hostname="decwrl"
  93.  
  94. case $STYPE in
  95.     bsd) cmd='hostname || uuname -l';;
  96.     sysv)cmd='uname -n || uuname -l || hostname';;
  97.     *)   cmd='uuname -l';;
  98. esac;
  99.  
  100. hostname=`sh -c "$cmd" 2>&-`
  101.  
  102. PATH=$NEWS:$PATH
  103. ############################################################################
  104. export PATH
  105. # ---------------------------------------------------------------------------
  106. trap exit 1 2 3 15
  107. trap 's=$?; rm -f $TMPDIR/arb.*.$$; exit $s' 0
  108. set `date`
  109. dat="$2$6"
  110. destination="${MAILER-mail} $summarypath"
  111.  
  112. ################################
  113. # Here are several expressions, each of which figures out approximately how
  114. # many people use this machine. Comment out all but 1 of them; pick the one
  115. # you like best. Initially the most universal but least reliable of them is
  116. # uncommented.
  117. PASSWD=$TMPDIR/arb.passwd.$$
  118. (ypcat passwd || cat /etc/passwd) > $PASSWD
  119.  
  120. # # ###### Scheme #1: fast but usually returns too big a number
  121. nusers=`awk -F: "BEGIN {N=0}\\$3>=$lowUID && \\$3<=$highUID{N=N+1}END{print N}" <$PASSWD`
  122.  
  123. # # ###### Scheme #2 (works with BSD systems)
  124. #nusers=`last | sed '/^wtmp begins/d; s/ .*//; /^$/d' | sort -u | wc -l`
  125.  
  126. # # ###### Scheme #3 (works with USG systems)
  127. #nusers=`who /etc/wtmp | sort -u +0 -1 | wc -l`
  128.  
  129. ################################
  130. #
  131. # Set up awk scripts;  these are too large to pass as arguments on most
  132. # systems.
  133. #
  134. # This awk script generates the actual output report.
  135. # We use 'sed' to substitute in the shell variables to save ourselves
  136. # endless hassle trying to find quoting/backslashing problems.
  137. #
  138. # The input to this script consists of two types of lines (pre-sorted):
  139. #
  140. #    (1) Active-file lines.  These have four fields:  newsgroup name,
  141. #        first existing article, last article number, 'y' or 'n'
  142. #        to allow/disallow posting.
  143. #            mod.mac 00001 00001 y
  144. #
  145. #    (2) .newsrc-derived lines.  These have three fields:  the newsgroup
  146. #        name, the user name and the articles-read information.  The latter
  147. #        can be arbitrarily complex.  It can also be arbitrarily long;
  148. #        this can potentially break either awk or sed, in which
  149. #        case the script will not work.
  150. #            mod.map joe 1-199
  151. #
  152. #    The script uses the type 1 lines to define the newsgroups
  153. #    and their active article ranges.  The .newsrc (type 2) lines are
  154. #    then used to deduce which users are reading that group (a group
  155. #    is being read if the last article seen is in that group's active
  156. #    article range).
  157. #
  158. sed "/^#/d
  159.      s/NUSERS/$nusers/g
  160.      s/HOSTNAME/$hostname/g
  161.      s/DATE/$dat/g" > $TMPDIR/arb.fmt.$$ << 'DOG'
  162. # makereport -- utility for "arbitron". Early versions were copied from a
  163. # similar script distributed with "subscribers.sh" by Blonder, McCreery, and
  164. # Herron.
  165. #
  166.     BEGIN    { rdrcount = 0 ; reader = "" ; grpcount = 0 ; realusers = 0}
  167. #
  168. # Active file line:  dispose of previous group (if any), record group, and
  169. # record first and last article numbers.  Set group's reader count to none.
  170.     NF == 4 { if (grpname != "") {
  171.             printf("%d %s\n",grpcount, grpname)
  172.           }
  173.           grpname = $1
  174.           grpfirst = $3
  175.           grplast = $2
  176.           grpcount = 0
  177.         }
  178. #
  179. # .newsrc line.  Break out the final number, which is the last article that
  180. # has actually been read.  This is a pretty good indicator of the person's
  181. # true interest in the group.  If 'lastread' for the group is a current
  182. # (unexpired) article, record a reader for that group.  Finally, record
  183. # the user as a "real" user of the news system.
  184. #
  185.     NF == 3 { if ($1 != grpname) next;
  186.           n1 = split($3, n2, "-")
  187.           n3 = split(n2[n1], n4, ",")
  188.           lastread = n4[n3]
  189.     if ((grpfirst != grplast) && (lastread >= grpfirst) && (lastread <= grplast)) {
  190.             grpcount++
  191.             if (realuser[$2] != 1) {
  192.                 realuser[$2] = 1
  193.                 realusers++
  194.             }
  195.           }
  196.         }
  197. #
  198. # End of file.  Print the report in 2 columns.
  199.     END    { printf("9999 Host\t\t%s\n","HOSTNAME")
  200.           printf("9998 Users\t\t%d\n",NUSERS)
  201.           printf("9997 NetReaders\t%d\n",realusers)
  202.           printf("9996 ReportDate\t%s\n","DATE")
  203.           printf("9995 SystemType\tnews-arbitron-2.4\n")
  204. # For reorganized network, report a group even if nobody reads it. This will
  205. # help us keep track of where the groups propagate.
  206.           printf("%d %s\n",grpcount, grpname)
  207.         }
  208. DOG
  209.  
  210. cat >$TMPDIR/arb.pwd.$$ <<'MOUSE'
  211. BEGIN    { seen["/"]=1; seen[""] = 1; }
  212.     { if (seen[$6]!=1) {
  213.         printf("if [ -r %s/.nn/rc ] ; then ", $6)
  214.         printf("sed -n '/^+/s/^. \([0-9]*\) \(.*\)/\2 %s \1/p'",$1)
  215.         printf(" <%s/.nn/rc;\n",$6)
  216.         printf("elif [ -r %s/.newsrc ] ; then ", $6)
  217.         printf("sed -n '/: [0-9]/s/:/ %s/p' <%s/.newsrc; fi\n",$1,$6)
  218.         seen[$6]=1;
  219.       }
  220. }
  221. MOUSE
  222.  
  223. # First, make sure we have an active file
  224. if [ -z "$NEWSHOST" ]
  225. then ACTIVE=$NEWS/active
  226. else ACTIVE=/tmp/arb.active.$$
  227.      rcp $NEWSHOST:$NEWS/active $ACTIVE
  228. fi
  229.  
  230. if [ ! -s $ACTIVE ]
  231. then
  232.     echo arbitron: ACTIVE file missing or empty. Cannot continue. >&2
  233.     (exit 1); exit
  234. fi
  235.  
  236. # Next, get the list of .newsrc files with duplicates and unreadable files
  237. # removed.
  238. awk -F: -f $TMPDIR/arb.pwd.$$ <$PASSWD | sh >$TMPDIR/arb.tmp.$$
  239.  
  240. # Check to make sure that we found some
  241. if [ -s $TMPDIR/arb.tmp.$$ ]
  242. then # See if "active" file has 4 fields or only two (pre-2.10.2)
  243.      set `sed 1q < $ACTIVE`
  244.      if [ $# -eq 2 ]
  245.      then egrep  '^[a-z][-0-9_a-z]*\.' $ACTIVE |
  246.       while read group last
  247.       do dir=`echo "$group" | sed 's;\.;/;g'`
  248.          first=`ls $SPOOL/$dir | grep '^[0-9]*' | sort -n | sed 1q`
  249.          case $STYPE in
  250.         usg) echo "$group $last ${first:-$last} X";;
  251.           *) echo "$group $last ${first-$last} X"
  252.          esac
  253.       done
  254.      else egrep '^[a-z][-0-9_a-z]*\.' $ACTIVE
  255.      fi |
  256.      sort - $TMPDIR/arb.tmp.$$ |
  257.      awk -f $TMPDIR/arb.fmt.$$ |
  258.      sort -nr |
  259.      sed '/^$/d
  260.       s/^999[0-9] //' |
  261.      $destination
  262. else echo arbitron: Unable to find any readable .newsrc files >&2
  263.      (exit 1); exit
  264. fi
  265.  
  266.