[net.sources] Pyramid's leafbatch script

csg@pyramid.UUCP (Carl S. Gutekunst) (03/07/87)

>>   In Pyramid ucb universe you can use the -l option to uux and it will
>>make a link to the original file instead of copying it...
>
>Actually, I am aware of this modification.  I believe Erik Fair has a
>mod for Berkeley uux which allows uux -l.

The '-l' option is standard in 4.3BSD UUCP, which is what Pyramid is shipping
these days. HoneyDanBer also has this capability, under the '-L' option.

Because it's short (well, sortof) and sweet (hey, *I* like it!), here is my
'leafbatch' script and it's related support files. It works with 4.3BSD UUCP
and HDB (change -l to -L). I have run it only with the BSD Bourne shell. It's
intended for 2.10.3; I haven't yet tried it with 2.11, although it should work
without modification.

There is one Pyramid idiom: I used the 'att date' command to generate time
stamps on the temporary batch files. Just about anything else could be used
instead. Look at the $STAMP variable, and modify to taste.

Please be merciful with this code; this is only the second time I've posted
sources, and youse peoples are tougher to please than my boss.... :-)

<csg>

: ------ CUT HERE ------ CUT HERE ------ CUT HERE ------ CUT HERE ------
: This is a shell archive.
: To unpack it, feed it to /bin/sh, NOT to /bin/csh.
:
: This archive includes the following files:
:	leafbatch
:	batch.patch
:	nn.hourly
:	sys
:
echo x - leafbatch
sed 's/^X//' >leafbatch <<'*-*-END-of-leafbatch-*-*'
X#! /bin/sh
X# '@(#)leafbatch	1.2	86/08/07'
X#
X# Summary:
X#	leafbatch batchname grade [site1] [site2] [site3] [site4] ...
X#
X# Description:
X#	Leaf sites: Given the name of a normal batch queueing file, this script
X#	batches and compresses the bundle into a local file, then uses the -l
X#	option of uux to queue the same batch for a list of sites. This is an
X#	alternative to csendbatch, which will batch and compress the same data
X#	once for every site.
X#
X#	The assumption is that this script will be run hourly from cron, and
X#	that the ~news/sys file will be set to batch to a dummy sitename that
X#	this script will use.
X#
X#	To prevent shipping out lots of tiny bundles, leafbatch will *not* do
X#	batching if there are fewer than 10 lines in the batch queueing file.
X#	To prevent a 1-article queue from getting stranded, two null articles
X#	are appended to the batch queue on each failure; so at worst, 4 fours
X#	will ellapse before the lone article is finally sent. (This requires a
X#	fixed version of batch, that does not gag on blank lines.)
X
Xif [ $# -lt 1 ]
Xthen
X	echo 'leafbatch: Missing arguments'
X	echo 'leafbatch batchname [-ggrade] [site1] [-ggrade] [site2] ...'
X	exit
Xfi
X
XLIM=100000
XPATH=:/usr/ucb:/bin:/usr/bin:/usr/new:/usr/local/bin
Xexport PATH
Xumask 022
XBATCH=$1
XGRADE=-gz
Xshift
X
Xcd /usr/spool/batch
Xif [ ! -s leaf_${BATCH}.work ]
Xthen
X	if [ ! -s leaf_$BATCH ]
X	then
X		exit
X	fi
X	if [ `wc -l < leaf_$BATCH` -lt 9 ]
X	then
X		echo >> leaf_$BATCH
X		echo >> leaf_$BATCH
X		exit
X	fi
Xfi
X
Xwhile [ -s leaf_$BATCH -o -s leaf_${BATCH}.work ]
Xdo
X	while STAMP=`att date +%y%m%d%H%M%S` ; [ -s ${BATCH}.$STAMP ]
X	do
X		sleep 1
X	done
X	(echo "#! cunbatch"; \
X	/usr/lib/news/batch leaf_$BATCH $LIM | compress ) >${BATCH}.$STAMP
X
X	error=$?
X	if [ $? -ne 0 ]
X	then
X		Mail -s "Status $error on ${BATCH}.$STAMP" usenet << EOF
XBatcher Failed. Leafbatch script Aborted.
XEOF
X		exit
X	fi
X
X	GRADE=-gz
X	for site
X	do
X		case $site in
X		-g*)	GRADE=$site; continue;;
X		esac
X
X		uux -r -l -z $GRADE $site!rnews \< !${BATCH}.$STAMP
X		error=$?
X		if [ $? -ne 0 ]
X		then
X			Mail -s "Status $error on ${BATCH}.$STAMP" usenet << EOF
XUux Failed. Leafbatch script continued for other hosts.
XEOF
X			exit
X		fi
X	done
X	rm ${BATCH}.$STAMP
Xdone
*-*-END-of-leafbatch-*-*
echo x - batch.patch
sed 's/^X//' >batch.patch <<'*-*-END-of-batch.patch-*-*'
XThe following patch to the 2.10.3 version of batch.c causes the utility to
Xignore blank lines in the batch file. This is used by the leafbatch script as
Xa crude but effective mechanism to prevent generation of many tiny batches.
X
X*** batch.c.orig	Wed Apr 17 10:34:04 1985
X--- batch.c	Tue Aug 12 14:30:13 1986
X***************
X*** 87,92
X  		cp = index(fname, '\n');
X  		if (cp)
X  			*cp = '\0';
X  		nfd = fopen(fname, "r");
X  		if (nfd == NULL) {
X  			perror(fname);
X
X--- 87,94 -----
X  		cp = index(fname, '\n');
X  		if (cp)
X  			*cp = '\0';
X+ 		if (fname[0] == '\0')
X+ 			continue;
X  		nfd = fopen(fname, "r");
X  		if (nfd == NULL) {
X  			perror(fname);
X***************
X*** 93,98
X  			continue;
X  		}
X  		(void) fstat(fileno(nfd), &sbuf);
X  		printf("#! rnews %ld\n", (long)sbuf.st_size);
X  		n = 0;
X  		while ((c = getc(nfd)) != EOF) {
X
X--- 95,102 -----
X  			continue;
X  		}
X  		(void) fstat(fileno(nfd), &sbuf);
X+ 		if (sbuf.st_size == 0L)
X+ 			continue;
X  		printf("#! rnews %ld\n", (long)sbuf.st_size);
X  		n = 0;
X  		while ((c = getc(nfd)) != EOF) {
*-*-END-of-batch.patch-*-*
echo x - nn.hourly
sed 's/^X//' >nn.hourly <<'*-*-END-of-nn.hourly-*-*'
X#!/bin/sh
X#
X#	Hourly script for the news -- <csg> Mon Apr 14 15:32:50 PST 1986
X
X#	Leaf sites: batch and queue everything every hour. Grading is used to
X#	make sure we don't try to ship the world every hour. Downstream sites
X#	that support grading can use this too. The rest take what they get....
X#
Xleafbatch ba   -gp altera bene ctnews cromemco isieng nsc triada -gE voder weitek
Xleafbatch comp -gr altera bene ctnews cromemco isieng nsc triada voder weitek
Xleafbatch misc -gt altera bene ctnews isieng nsc triada voder
Xleafbatch news -gr altera bene ctnews cromemco isieng nsc triada voder weitek
Xleafbatch rec  -gt altera bene ctnews isieng triada voder
Xleafbatch sci  -gr altera bene ctnews isieng nsc triada voder
Xleafbatch soc  -gt altera bene ctnews isieng triada voder
Xleafbatch talk -gv bene ctnews isieng pyrtech triada voder
*-*-END-of-nn.hourly-*-*
echo x - sys
sed 's/^X//' >sys <<'*-*-END-of-sys-*-*'
X# Structure for batching to Leaf sites
X#
Xleaf_ba:ca,ba,world:F:
Xleaf_comp:comp,world,na,usa,ca,!ca.all,ba,!ba.all,net.sources,\
X	mod.ai,mod.amiga,mod.comp-soc,mod.compilers,mod.computers,\
X	mod.conferences,mod.graphics,mod.human-nets,mod.mac,mod.newprod,\
X	mod.os,mod.protocols,mod.risks,mod.sources,mod.std,mod.techreports,\
X	mod.telecom,mod.unix,mod.vlsi:F:
Xleaf_misc:misc,world,na,usa,ca,!ca.all,ba,!ba.all:F:
Xleaf_news:news,world,na,usa,ca,!ca.all,ba,!ba.all,\
X	mod.announce,mod.map,mod.newslists:F:
Xleaf_rec:rec,world,na,usa,ca,!ca.all,ba,!ba.all,\
X	mod.mag,mod.movies,mod.music,mod.rec,mod.recipes:F:
Xleaf_sci:sci,world,na,usa,ca,!ca.all,ba,!ba.all,mod.psi:F:
Xleaf_soc:soc,world,na,usa,ca,!ca.all,ba,!ba.all:F:
Xleaf_talk:talk,world,na,usa,ca,!ca.all,ba,!ba.all,\
X	mod.philosophy,mod.politics:F:
*-*-END-of-sys-*-*
exit