home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / CNEWS / _CNEWS.TAR / usr / lib / newsbin / expire / recovact < prev    next >
Encoding:
Text File  |  1994-09-02  |  1.3 KB  |  63 lines

  1. #! /bin/sh
  2. # Try to recover 2nd field of active file.
  3.  
  4. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  5. . ${NEWSCONFIG-/var/lib/news/bin/config}
  6.  
  7. PATH=$NEWSCTL/bin:$NEWSBIN/expire:$NEWSBIN:$NEWSPATH ; export PATH
  8. umask $NEWSUMASK
  9.  
  10. cd $NEWSCTL || { echo "$0: can't cd to $NEWSCTL" >&2; exit 1; }
  11.  
  12. # check active file format
  13. set ""`sed 1q active`
  14. case $# in
  15. 4)    ;;
  16. *)    echo "$0: active file has other than 4 fields" >&2
  17.     exit 1 ;;
  18. esac
  19.  
  20. # lock news system
  21. lock="$NEWSCTL/LOCK"
  22. ltemp="$NEWSCTL/L.$$"
  23. echo $$ >$ltemp
  24. trap "rm -f $ltemp ; exit 0" 0 1 2 15
  25. while true
  26. do
  27.     if newslock $ltemp $lock
  28.     then
  29.         trap "rm -f $ltemp $lock ; exit 0" 0 1 2 15
  30.         break
  31.     fi
  32.     sleep 30
  33. done
  34.  
  35. while read group max min fourth
  36. do
  37.     dir=`echo $group | tr . / `    # map ng name to directory name
  38.     new=
  39.     if test -d $NEWSARTS/$dir
  40.     then
  41.         new=`ls $NEWSARTS/$dir | egrep '^[0-9]+$' | sort -n | tail -1`
  42.     fi
  43.     case "$new" in
  44.     "")    new=$max    ;;    # no files -- preserve old value
  45.     *)    if test "$new" -lt "$max"    # old value more recent (!)
  46.         then
  47.             new="$max"
  48.         fi
  49.         ;;
  50.     esac
  51.     dots="`echo $max | tr 0123456789 ..........`"
  52.     max="`expr 0000000000$new : '.*\('$dots'\)$'`"    # preserve length
  53.  
  54.     echo $group $max $min $fourth
  55. done <active >active.new
  56.  
  57. # replace active, carefully
  58. rm -f active.old
  59. ln active active.old
  60. mv active.new active
  61.  
  62. exit 0
  63.