Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site lsuc.UUCP
Path: utzoo!utcs!mnetor!lsuc!msb
From: msb@lsuc.UUCP (Mark Brader)
Newsgroups: net.news
Subject: Re: limiting news to certain hours of the day?
Message-ID: <757@lsuc.UUCP>
Date: Mon, 19-Aug-85 20:16:23 EDT
Article-I.D.: lsuc.757
Posted: Mon Aug 19 20:16:23 1985
Date-Received: Tue, 20-Aug-85 06:27:34 EDT
References: <726@lsuc.UUCP> <148@kitc.UUCP> <137@ihnp3.UUCP>
Reply-To: msb@lsuc.UUCP (Mark Brader)
Organization: Law Society of Upper Canada, Toronto
Lines: 125
Keywords: news forwarding batching
Summary: Here's our version of it


We receive almost all of our news in compressed batches.
We have replaced cunbatch by the following shell script:
-------------------------------- cut here ---------------------------------

cd /usr/spool/batchnews
name=cunb-$$
cat >making-$$
mv making-$$ $name
-------------------------------- eher tuc ---------------------------------

(/usr/spool/batchnews is generally-writable on our system, analogous to
/usr/spool/uucppublic.  I don't know what you do if this is unacceptable.)

The fun part is the shell script to uncompress them.  We want news to
appear on the system fairly quickly outside of working hours, and have
chosen 1 hour as the acceptable delay.  So we run the script below,
called "unspoolnews", once an hour outside working hours.

But the first run in the evening may take well over an hour, and we
could end up with two or more news-unpacks competing, especially the
day after any kind of delay.  So to prevent this, unspoolnews writes a
lock file called LCK.

But if an unspoolnews crashes for some reason (system crash, for instance),
we don't want the LCK file to hang around stopping the next run.  The
solution is to check when the LCK file was last written.  If it is more
than 40 minutes ago, or (for simplicity) not this month, we assume that
the older unspoolnews has gone away, and throw out the old LCK.
Note that the 40-minute checking is done right in the shell using bc.

If new batches arrive while unspoolnews is running, it will unspool them
when it's finished the ones that were then when it started.

We assume that there are some people who want to hear about certain
errors that may be produced by rnews or compress.  The code catches
stderr from both programs.  Any error from compress is considered worth
telling about; certain messages from rnews are considered ignorable, and
are only mentioned if there are any other errors.  The behavior is to
send mail to the people mentioned in $WHOM if anything not containing
the strings in $EXCLUDEMSGS shows up in stderr of rnews, or if anything
is in stderr of compress.  You will want to configure this according to
what you think is serious.  At our site it is governed by the fact that
our junk directory is unwritable, for instance, and we know it.

Two further notes: zcat is a link to compress -d; and mail -s mails
an article with the specified subject line.  You may have to change
these.  We run Edition VII, essentially V7, and this is Bourne Shell code.
Here's unspoolnews:

-------------------------------- cut here ---------------------------------
PATH=/bin:/usr/bin:/usr/ucb
WHOM="news dave"
EXCLUDEMSGS="Newsgroups in active, but not sys
Cannot install article as
failed, errno 13, check dir permissions.
rejected. linecount expected
Article too old
Unknown newsgroup
No valid newsgroups found, moved to junk"
cd /usr/spool/batchnews

if test -r LCK && sh -c '
	IFS=":$IFS"
	cat /dev/null
	set x`ls -lu LCK 2>/dev/null`
	MinU="$6 * 1920 + $7 * 60 + $8"
	MonU="$5"
	
	set x`ls -l LCK 2>/dev/null`
	MinL="$6 * 1920 + $7 * 60 + $8"
	MonL="$5"
	
	if test "$MonU" != "$MonL" \
			-o `echo "(($MinU)-($MinL))/40" | bc 2>&1` != 0
	then
		rm -f LCK
	fi
	test -r LCK'

then
	exit 0
fi

while :
do
	for i in cunb-*
	do
		if test "$i" = "cunb-*"
		then
			rm -f LCK .err-?-$$ 2>/dev/null
			exit 0
		else
			>LCK
			mv $i $$-$i
			if test ! -s $$-$i ||
				zcat <$$-$i 2>.err-z-$$ | rnews 2>.err-r-$$ &&
				test ! -s .err-z-$$ &&
				(fgrep -v "$EXCLUDEMSGS" .err-r-$$ >.err-s-$$
				 test ! -s .err-s-$$)
			then
				rm $$-$i
			else
				mv $$-$i .$i
				(file `pwd`/.$i
					ls -l `pwd`/.$i
					cat .err-[sz]-$$
					if test -s .err-r-$$
					then
						echo "
		Full error listing:
"
						cat .err-[rz]-$$
					fi) |
					mail -s "zcat or rnews error!" $WHOM
				rm .err-?-$$
			fi
		fi
	done
done
-------------------------------- eher tuc ---------------------------------

		 { decvax | ihnp4 | watmath | ... } !utzoo!lsuc!msb
		    also via { hplabs | amd | ... } !pesnta!lsuc!msb
Mark Brader		and		   uw-beaver!utcsri!lsuc!msb