home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / maint / newsdaily < prev    next >
Text File  |  1995-04-27  |  5KB  |  227 lines

  1. #! /bin/sh
  2. # newsdaily - daily housekeeping chores
  3.  
  4. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  5. . ${NEWSCONFIG-/etc/news/bin/config}
  6.  
  7. PATH=$NEWSCTL/bin:$NEWSBIN/maint:$NEWSBIN:$NEWSPATH ; export PATH
  8. umask $NEWSUMASK
  9.  
  10. gripes="/tmp/ngrip$$"
  11. tmp="/tmp/ndai$$"
  12. sus="/tmp/suspects$$"
  13. trap "rm -f $gripes $tmp $sus ; trap 0 ; exit 0" 0 1 2 15
  14. >$gripes
  15.  
  16. cd $NEWSCTL
  17.  
  18. # keep one generation of log -- it's big
  19. rm -f log.o log.o.Z
  20. mv log log.o
  21. touch log
  22. # log.o gets compressed below
  23.  
  24. # keep several generations of other logs for statistics and troubleshooting
  25. logroll -o errlog
  26. logroll -o batchlog
  27.  
  28. # report any errors
  29. sleep 500            # hope that errlog.o is quiescent after this
  30. if test -s errlog.o
  31. then
  32.     (
  33.         echo "errlog.o"
  34.         echo ---------
  35.         cat errlog.o
  36.         echo ---------
  37.         echo
  38.     ) >>$gripes
  39. fi
  40.  
  41. # look for input anomalies
  42. cd $NEWSARTS/in.coming
  43. find . -type f -mtime +1 -print | sed 's;^\./;;' | egrep -v '^bad/' >$tmp
  44. if test -s $tmp        # old non-bad files lying about
  45. then
  46.     (
  47.         echo 'old input files:'
  48.         ls -ldtr `cat $tmp`
  49.         echo
  50.     ) >>$gripes
  51. fi
  52. find bad -type f -name '[0-9]*' -mtime -2 -print >$tmp    # recent bad batches
  53. if test -s $tmp
  54. then
  55.     (
  56.         echo 'recent bad input batches (perhaps worth investigation):'
  57.         ls -ldtr `cat $tmp`
  58.         echo
  59.     ) >>$gripes
  60. fi
  61. find bad -type f -name '[0-9]*' -mtime +7 -exec rm -f '{}' ';'
  62. cd $NEWSCTL
  63.  
  64. # look for output anomalies
  65. cd $NEWSARTS/out.going
  66. find . -type f -name 'togo*' -size +0 -mtime +1 -print >$tmp
  67. if test -s $tmp
  68. then
  69.     (
  70.         echo 'batching possibly stalled for sites:'
  71.         sed 's;^\./\([^/]*\)/.*;\1;' $tmp | sort -u
  72.         echo
  73.     ) >>$gripes
  74. fi
  75. cd $NEWSCTL
  76. no=0
  77. if test -f batchlog.o
  78. then
  79.     no=`egrep 'disk too full' batchlog.o | wc -l`
  80. fi
  81. if test " $no" -gt 0
  82. then
  83.     (
  84.         echo "space shortage(s) limited batching $no times"
  85.         echo
  86.     ) >>$gripes
  87. fi
  88.  
  89. # do a quick check of the active file
  90. checkactive -q >$tmp
  91. if test -s $tmp
  92. then
  93.     (
  94.         echo 'checkactive reports problems in active file:'
  95.         cat $tmp
  96.         echo
  97.     ) >>$gripes
  98. fi
  99.  
  100. # sweep log file, once, for suspect lines
  101. egrep '`
  102. ancient
  103. future
  104. unparsable
  105. header
  106. space in
  107. Message-ID' log.o >$sus
  108.  
  109. # compress the old log file, now that we're done with it
  110. compress log.o
  111.  
  112. # look for problem newsgroups on input (can miss cross-posted articles)
  113. egrep 'junked|junk group is excluded' $sus | sed 's/.*`\(.*\)'"'"'.*/\1/' |
  114.     sort | uniq -c | sort -nr | sed 5q >$tmp
  115. if test -s $tmp
  116. then
  117.     (
  118.         echo 'leading five unknown newsgroups by number of articles:'
  119.         cat $tmp
  120.         echo
  121.     ) >>$gripes
  122. fi
  123. egrep unapproved $sus | sed 's/.*`\(.*\)'"'"'.*/\1/' | sort |
  124.     uniq -c | sort -nr | sed 5q >$tmp
  125. if test -s $tmp
  126. then
  127.     (
  128.         echo 'top five supposedly-moderated groups with unmoderated postings:'
  129.         cat $tmp
  130.         echo
  131.     ) >>$gripes
  132. fi
  133. egrep 'no subscribed' $sus | sed 's/.*`\(.*\)'"'"'.*/\1/' | sort |
  134.     uniq -c | sort -nr | sed 5q >$tmp
  135. if test -s $tmp
  136. then
  137.     (
  138.         echo 'leading five unsubscribed newsgroups:'
  139.         cat $tmp
  140.         echo
  141.     ) >>$gripes
  142. fi
  143.  
  144. # And other signs of problems.
  145. egrep 'ancient|too far in the future|unparsable Date' $sus | egrep ' - ' |
  146.     awk '{print $4}' | sort | uniq -c | sort -nr | sed 5q >$tmp
  147. if test -s $tmp
  148. then
  149.     (
  150.         echo 'leading five sites sending stale/future/misdated news:'
  151.         cat $tmp
  152.         echo
  153.     ) >>$gripes
  154. fi
  155. egrep ' (no|empty) .* header|contains non-|Message-ID|space in' $sus |
  156.     egrep ' - ' | awk '{print $4}' | sort | uniq -c | sort -nr |
  157.     sed 5q >$tmp
  158. if test -s $tmp
  159. then
  160.     (
  161.         echo 'leading five sites sending news with bad headers:'
  162.         cat $tmp
  163.         echo
  164.     ) >>$gripes
  165. fi
  166.  
  167. # send it
  168. report 'newsdaily report' <$gripes
  169.  
  170. # and do other daily chores
  171. $NEWSBIN/relay/dodelayed
  172.  
  173. # if there are dead-newsgroup directories to be deleted when empty, try them
  174. if test -s dirs.tbd
  175. then
  176.     while read dir
  177.     do
  178.         if test ! -d $NEWSARTS/$dir
  179.         then
  180.             continue        # NOTE CONTINUE
  181.         fi
  182.         cd $NEWSARTS/$dir
  183.         if test " `ls | egrep '^[0-9]+$' | wc -l`" -gt 0
  184.         then
  185.             # articles remain, try again tomorrow...
  186.             echo "$dir"
  187.         else
  188.             # looks like we can scrap it...
  189.             rm -f .[a-zA-Z]* *.* $NEWSOV/$dir/.overview
  190.             cd $NEWSARTS
  191.             rmdir $dir 2>/dev/null
  192.             while test `expr "$dir" : '.*/.*'` -gt 0
  193.             do
  194.                 dir=`expr "$dir" : '\(.*\)/[^/]*'`
  195.                 rmdir $dir 2>/dev/null
  196.             done
  197.             cd $NEWSOV
  198.             rmdir $dir 2>/dev/null
  199.             while test `expr "$dir" : '.*/.*'` -gt 0
  200.             do
  201.                 dir=`expr "$dir" : '\(.*\)/[^/]*'`
  202.                 rmdir $dir 2>/dev/null
  203.             done
  204.         fi
  205.     done <dirs.tbd >dirs.ttd
  206.     cd $NEWSCTL
  207.     mv dirs.ttd dirs.tbd
  208. fi
  209.  
  210. # if symlinks.used is older than the oldest article, get rid of it
  211. if test -f symlinks.used
  212. then
  213.     usedat="`cat symlinks.used`"
  214.     case "$usedat" in
  215.     '')    usedat=0    ;;
  216.     esac
  217.     oldest="`sed 1q history | sed 's/^[^    ]*    //' | sed 's/[~    ].*//'`"
  218.     case "$oldest" in
  219.     '')    oldest=`now`    ;;
  220.     esac
  221.     # throw in 10000s for a safety margin
  222.     obsoleteness=`echo "$usedat $oldest" | awk '{ print $1 - $2 + 10000 }'`
  223.     case "$obsoleteness" in
  224.     -*)    rm -f symlinks.used    ;;
  225.     esac
  226. fi
  227.