home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / wCNews_1.0.30.lha / contrib / arbitron / POSTER
Encoding:
Internet Message Format  |  1992-11-03  |  9.1 KB

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