home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / unix / volume03 / newspace < prev    next >
Encoding:
Internet Message Format  |  1988-09-11  |  5.5 KB

  1. From: talcott!seismo!amdahl!gam (G A Moffett)
  2. Subject: newspace - determine newsgroup disk usage
  3. Newsgroups: mod.sources
  4. Approved: jpn@panda.UUCP
  5.  
  6. Mod.sources:  Volume 3, Issue 107
  7. Submitted by: talcott!seismo!amdahl!gam (G A Moffett)
  8.  
  9.  
  10. : This is a shar archive.  Extract with sh, not csh.
  11. echo x - README
  12. sed -e 's/^X//' > README << '!Funky!Stuff!'
  13. XDESCRIPTION
  14. X    Newspace(1) reports the disk space used by Usenet newsgroups.
  15. X    It is more intellegent than a du(1) of the directories of the
  16. X    newsgroups; see the man page for details.
  17. X
  18. XCONFIGURATION EXPECTATIONS
  19. X    The shell script is set up for the default news configuration;
  20. X    however, if yours is different, inspect the shell script's use
  21. X    of the environment variables "newsdir" and "active", which
  22. X    give the directory under which the newsgroups are and the
  23. X    location of the active file.
  24. X
  25. XSYSTEM EXPECTATIONS
  26. X    The shell script by default uses the System V cut(1) and xargs(1)
  27. X    commands; if you don't have cut(1), some commented-out code is
  28. X    provided to imitate its function.  Edit accordingly.
  29. X
  30. X    A public domain xargs(1) has been distributed separatedly
  31. X    for non-System V Unixes.  As with cut(1), some
  32. X    commented-out code in the shell script is provided to imitate
  33. X    xargs if you don't have it (although use of xargs is encouraged!).
  34. X
  35. XCOMMENT
  36. X    One notable feature of this shell script is that it contains the
  37. X    longest pipeline-command I think I have ever seen; all the work
  38. X    is done, in fact, by a single pipeline.
  39. X
  40. XHISTORY
  41. X    The original newspace was written by me and distributed to
  42. X    the San Francisco Bay Area sites via ba.news in January, 1986,
  43. X    partly for testing purposes.  David St. Pierre (ptsfa!dsp)
  44. X    suggested some improvements and enhancements (thanks, David),
  45. X    which are included here.  Before it's posting to mod.sources,
  46. X    John P. Nelson (panda!jpn) provided an alternative for the
  47. X    xargs usage (thanks, John).
  48. X
  49. XBUGS
  50. X    I have no bugs to report; however I would like to hear of any
  51. X    bugs or enhancements for this shell script, and any comments
  52. X    and improvements for the manual page.  (One obvious enhancement,
  53. X        perhaps, is for newspace to report the size of particular
  54. X        newsgroups, instead of all of them at once).
  55. X
  56. X
  57. X                Gordon A. Moffett
  58. X                {ihnp4,seismo,hplabs}!amdahl!gam
  59. X
  60. !Funky!Stuff!
  61. echo x - newspace.1
  62. sed -e 's/^X//' > newspace.1 << '!Funky!Stuff!'
  63. X.\" @(#)newspace.1    1.2 1/21/86 21:36:09 - Amdahl/UTS
  64. X.TH NEWSPACE 1 "Local"
  65. X.SH NAME
  66. Xnewspace \- show how much space each newsgroup uses
  67. X.SH SYNOPSIS
  68. X.B /usr/lib/news/newspace
  69. X.SH DESCRIPTION
  70. X.I Newspace
  71. Xis a shell script which
  72. Xdisplays the total disk space used by the articles in
  73. Xeach Usenet newsgroup.
  74. XWhile
  75. X.IR du (1)
  76. Xis used to measure the disk space, the report is
  77. X.I not
  78. Xa
  79. X.I du
  80. Xof all the newgroup directories, but the disk space used
  81. Xby that newsgroup alone;
  82. X.IR eg ,
  83. Xthe total for net.music does not include the total for
  84. Xnet.music.gdead.
  85. X.P
  86. XThe output is sorted so that largest newsgroups are
  87. Xdisplayed first.
  88. X.P
  89. X.SH FILES
  90. X.TP 25
  91. X/usr/lib/news/archive
  92. Xlist of newsgroups to measure
  93. X.TP 25
  94. X/usr/spool/news/\(**
  95. Xwhere all newsgroups are stored
  96. X.SH SEE ALSO
  97. Xdu(1)
  98. X.SH DIAGNOSTICS
  99. XSelf-explanetory.  In particular, the list of newsgroups to
  100. Xmeasure is taken from /usr/lib/news/active; and the
  101. Xnewsgroups are expected to be found under /usr/spool/news.
  102. X.SH BUGS
  103. !Funky!Stuff!
  104. echo x - newspace.sh
  105. sed -e 's/^X//' > newspace.sh << '!Funky!Stuff!'
  106. X
  107. X# print filespace used by each newsgroup, largest-first
  108. X
  109. Xactive=/usr/lib/news/active
  110. Xnewsdir=/usr/spool/news
  111. X
  112. X# make sure needed files/directories are available
  113. X
  114. Xif [ ! -f $active ]
  115. Xthen
  116. X    echo "$0: can't find active file" 1>&2
  117. X    exit 1
  118. Xfi
  119. X
  120. Xif [ ! -r $active ]
  121. Xthen
  122. X    echo "$0: can't open active file" 1>&2
  123. Xfi
  124. X
  125. Xif [ ! -d $newsdir ]
  126. Xthen
  127. X    echo "$0: no $newdir directory!" 1>&2
  128. X    exit 1
  129. Xfi
  130. X
  131. Xcd $newsdir
  132. X
  133. X# the first section of the pipeline meaures the filespace under each
  134. X#       directory which corresponds to a newsgroup name in the
  135. X#       active file
  136. X
  137. X# the following cat-while loop is supplied in case you dont have cut(1);
  138. X#       it's output should be piped into xargs
  139. X    
  140. X#cat $active | while read ng junk    # fetch newsgroups
  141. X#do
  142. X#    echo $ng
  143. X#done |
  144. X
  145. X# another choice: John Nelson (panda!jpn) supplied the following
  146. X#       alternative for the cut-tr-xargs-du pipeline; its output
  147. X#       should be piped into awk for the large awkscript below
  148. X
  149. X#du -s `awk '{ print $1 }' $active | tr '.' '/'` |
  150. X
  151. X# OK, here's the vanilla System V version ...
  152. X
  153. Xcut -d" " -f1 -s $active |              # substitutions for this supplied above
  154. X    tr '.' '/' |            # cvt newsgroup names to dirs
  155. X    xargs du -s |            # measure them all
  156. X
  157. X# this awk program takes these measurements of the
  158. X# directories and redistributes the weights of specific newsgroups;
  159. X# that is, the size of net/music/gdead is subtracted from the
  160. X# the size of net/music, and so on.
  161. X
  162. Xawk '
  163. X    { newsgroups[$2] = $1 }
  164. XEND {
  165. X    for (ng in newsgroups) {
  166. X        n = split(ng, l, "/")
  167. X        tng = l[1]        # parent newsgroups of ng
  168. X
  169. X        # look at each parent (?ancestor) of this newsgroup
  170. X
  171. X        for (i = 2; i <= n; i++) {
  172. X
  173. X            # subtract total of this newsgroup from total
  174. X            #    of parent newsgroups
  175. X
  176. X            if (newsgroups[tng] > 0)
  177. X                newsgroups[tng] -= newsgroups[ng]
  178. X            tng = tng "/" l[i]
  179. X        }
  180. X    }
  181. X
  182. X    # print them out (only non-empty ones, tab-separated)
  183. X
  184. X    for (ng in newsgroups) {
  185. X        if (newsgroups[ng] > 0)
  186. X            print newsgroups[ng], "\t", ng
  187. X    }
  188. X}' |
  189. X    tr '/' '.'  |        # restore standard newsgroup names
  190. X    sort +0nr        # largest newsgroups first
  191. !Funky!Stuff!
  192. exit
  193.  
  194.