home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 400-499 / ff473.lzh / CNewsSrc / cnews_src.lzh / batch / sendbatches < prev    next >
Text File  |  1990-12-22  |  4KB  |  183 lines

  1. #! /bin/sh
  2. # Master batching control.
  3.  
  4. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  5. . ${NEWSCONFIG-/usr/lib/news/bin/config}
  6.  
  7. PATH=$NEWSCTL/bin:$NEWSBIN/batch:$NEWSBIN:$NEWSPATH ; export PATH
  8. umask $NEWSUMASK
  9.  
  10. origpath="$PATH"
  11.  
  12. parms=$NEWSCTL/batchparms
  13. log=$NEWSCTL/batchlog
  14.  
  15. # lock against multiple simultaneous execution
  16. lock="$NEWSCTL/LOCKbatch"
  17. ltemp="$NEWSCTL/L.$$"
  18. echo $$ >$ltemp
  19. trap "rm -f $ltemp ; exit 0" 0 1 2 15
  20. if newslock $ltemp $lock
  21. then
  22.     trap "rm -f $ltemp $lock ; exit 0" 0 1 2 15
  23. else
  24.     exit 0
  25. fi
  26.  
  27. cd $NEWSARTS/out.going
  28.  
  29. # Determine what systems are being requested, in what order.
  30. case "$1"
  31. in
  32.     -d)
  33.     debug=yes
  34.     shift
  35.     ;;
  36. esac
  37. case $#
  38. in
  39.     0)
  40.     if egrep '^/default/[     ]' $parms >/dev/null    # default line found
  41.     then
  42.         syses=`ls -tr | egrep -v '^[@.]'`    # oldest first
  43.     else
  44.         syses="`egrep '^[^/#]' $parms | awk '{ print $1 }'`"
  45.     fi
  46.     ;;
  47.  
  48.     *)
  49.     syses="$*"
  50.     ;;
  51. esac
  52. case $debug
  53. in
  54.     yes)
  55.     for sys in $syses
  56.     do
  57.         echo $sys
  58.     done
  59.     exit 0
  60.     ;;
  61. esac
  62.  
  63. # Start up logging.
  64. date >>$log
  65.  
  66. # Run through them.
  67. for sys in $syses
  68. do
  69.     # Move into his directory, include it in search path.
  70.     here=$NEWSARTS/out.going/$sys
  71.     if test ! -d $here
  72.     then
  73.         echo "$0: cannot find batch directory for \`$sys'" |
  74.                             mail $NEWSMASTER
  75.         continue
  76.     fi
  77.     cd $here
  78.     PATH=$here:$origpath ; export PATH
  79.     NEWSSITE=$sys ; export NEWSSITE        # For site-specific programs.
  80.     NEWSSITEDIR=$here ; export NEWSSITEDIR    # ditto
  81.  
  82.     # Is there anything to do?
  83.     files=`echo togo*`
  84.     if test "$files" = 'togo*' || test "$files" = "togo" -a ! -s togo
  85.     then
  86.         continue            # no
  87.     fi
  88.  
  89.     # Pick up the batchparms line.
  90.     ctlline="`egrep \"^$sys[     ]\" $parms | sed 1q`"
  91.     if test " $ctlline" = " "
  92.     then
  93.         ctlline="`egrep '^/default/[     ]' $parms | sed 1q`"
  94.     fi
  95.     set $ctlline
  96.     if test " $#" -ne 6
  97.     then
  98.         echo "$0: bad or missing batchparms line for \`$sys'" |
  99.                             mail $NEWSMASTER
  100.         continue
  101.     fi
  102.     batchsize=$2
  103.     limit=$3
  104.     batcher=$4
  105.     muncher=$5
  106.     sender=$6
  107.  
  108.     # How many to send?
  109.     outstand=`queuelen $sys`
  110.     nbatch=`expr $limit - $outstand`
  111.     roomfor=`spacefor $batchsize outbound $sys`
  112.     if test " $nbatch" -gt " $roomfor"
  113.     then
  114.         nbatch=$roomfor
  115.     fi
  116.  
  117.     # If not allowed to send, remember reason.
  118.     status='batches flowing'
  119.     if test " $nbatch" -le 0
  120.     then
  121.         if test " $roomfor" -le 0
  122.         then
  123.             status='disk too full for batching'
  124.         else
  125.             status='queue full, no recent movement'
  126.         fi
  127.     fi
  128.  
  129.     # Try sending some.
  130.     while test " $nbatch" -gt 0
  131.     do
  132.         # Does he have batches prepared already?
  133.         if test "`echo togo.[0-9]`" = 'togo.[0-9]'
  134.         then
  135.             # No -- need some more batches.
  136.             if test ! -s togo && test ! -s togo.more &&
  137.                             test ! -s togo.next
  138.             then
  139.                 break        # Nothing left to do.
  140.             fi
  141.             batchsplit $batchsize
  142.         fi
  143.  
  144.         # Send some batches.
  145.         them=`ls | egrep '^togo\.[0-9]' | sed "${nbatch}q"`
  146.         for f in $them
  147.         do
  148.             ( ( cd $NEWSARTS ; $batcher $here/$f ) | $muncher |
  149.                         $sender $sys ) >/tmp/nb$$ 2>&1
  150.             if test $? -eq 0 -a ! -s /tmp/nb$$
  151.             then
  152.                 rm -f $f /tmp/nb$$
  153.             else
  154.                 (
  155.                     echo "$0: batching $f for \`$sys' failed"
  156.                     cat /tmp/nb$$
  157.                     echo "$0: aborting"
  158.                 ) | mail $NEWSMASTER
  159.                 exit 1
  160.             fi
  161.         done
  162.         ndone=`echo $them | wc -w`
  163.         nbatch=`expr $nbatch - $ndone`
  164.  
  165.         # Recheck the space -- it can fall for other reasons.
  166.         roomfor=`spacefor $batchsize outbound $sys`
  167.         if test " $nbatch" -gt " $roomfor"
  168.         then
  169.             nbatch=$roomfor
  170.         fi
  171.     done
  172.  
  173.     # Report status, if appropriate.
  174.     nart=`cat togo* | wc -l | awk '{print $1}'`
  175.     if test " $nart" -gt 0
  176.     then
  177.         echo "$sys    backlog $nart ($status)" >>$log
  178.     fi
  179. done
  180.  
  181. date >>$log
  182. echo >>$log
  183.