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

  1. #! /bin/sh
  2. # doexpire - overall administration for expire
  3.  
  4. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  5. . ${NEWSCONFIG-/etc/news/bin/config}
  6.  
  7. PATH=$NEWSCTL/bin:$NEWSBIN/expire:$NEWSBIN/nov:$NEWSBIN:$NEWSPATH; export PATH
  8. umask $NEWSUMASK
  9.  
  10. dor='?'
  11. opts=
  12. aux=yes
  13. histdir=$NEWSCTL
  14. for dummy
  15. do
  16.     case "$1" in
  17.     -r)    dor=yes ; opts="$opts -r"    ;;
  18.     -f)    dor=no                ;;
  19.     -e)    aux=no                ;;
  20.     --)                    ;;
  21.     -a)    opts="$opts $1 $2" ; shift    ;;
  22.     -H)    opts="$opts $1 $2"
  23.         histdir=$2
  24.         shift
  25.         ;;
  26.     -*)    opts="$opts $1"            ;;
  27.     *)    break                ;;
  28.     esac
  29.     shift
  30. done
  31. case $# in
  32. 0)    ;;
  33. *)    echo "$0: unknown arguments \`$*'" >&2 ; exit 2    ;;
  34. esac
  35.  
  36. if test -f $NEWSCTL/symlinks.used
  37. then
  38.     opts="$opts -l"
  39. fi
  40.  
  41. lock -o LOCKexpire $$ || {
  42.     echo "$0: doexpire apparently already running, won't start another" |
  43.                             report 'two doexpires'
  44.     exit 0
  45. }
  46. status=1
  47. trap 'unlock LOCKexpire ; trap 0 ; exit $status' 0 1 2 15
  48.  
  49. if test " `spacefor 1 archive`" -le 0
  50. then
  51.     (
  52.         echo "$0:"
  53.         echo "    Space shortage in archiving area!"
  54.         echo "    Unable to archive old articles -- holding them in"
  55.         echo "    current directories using \`expire -h'.  If shortage"
  56.         echo "    persists, human action is urgently needed."
  57.     ) | report -u "archiving-area space shortage"
  58.     opts="$opts -h"
  59. fi
  60.  
  61. cd $histdir
  62. case "$dor" in
  63. '?')    ropt=-r                # tentatively
  64.     for counter in x x x x        # four tries
  65.     do
  66.         rm -f history.o        # it's about to vanish anyway
  67.         size="`sizeof history history.pag history.dir`"
  68.         if test " `spacefor $size control`" -gt 0
  69.         then
  70.             ropt=
  71.             break
  72.         fi
  73.         sleep 600        # and hope it will improve
  74.     done
  75.     if test " $ropt" = " -r"
  76.     then
  77.         (
  78.             echo "$0:"
  79.             echo "    SEVERE SPACE SHORTAGE in $histdir !"
  80.             echo "    Unable to rebuild history files due to insufficient"
  81.             echo "    space for temporaries -- resorting to \`expire -r'."
  82.             echo "    Growth of the history files will make things worse;"
  83.             echo "    if shortage persists, human action is urgently needed."
  84.         ) | report -u "$NEWSCTL space shortage"
  85.         dor=yes
  86.         opts="$opts -r"
  87.     else
  88.         dor=no
  89.     fi
  90.     ;;
  91. esac
  92. case "$dor" in
  93. yes)    aux=no    ;;
  94. esac
  95.  
  96. expire $opts $NEWSCTL/explist 2>/tmp/doex$$
  97.  
  98. # don't run auxiliaries if this is a panic expire
  99. case "$aux" in
  100. no)    ;;
  101. *)    upact 2>>/tmp/doex$$
  102.     expov 2>>/tmp/doex$$
  103.     ;;
  104. esac
  105.  
  106. if test -s /tmp/doex$$
  107. then
  108.     report -u 'possible expire problems' </tmp/doex$$
  109. else
  110.     status=0
  111. fi
  112. rm -f /tmp/doex$$
  113. # don't remove history.o -- it reserves space for the next rebuild's history.n
  114.