Newsgroup: news.sysadmin


Path: icdoc!tsun4.doc.ic.ac.uk!zmact61
From: zmact61@tsun4.doc.ic.ac.uk.doc.ic.ac.uk (D Spinellis)
Newsgroups: news.sysadmin,alt.sources
Subject: Re: How to be a bridge between USENET & mailing list
Summary: A shell script that does part of what you want
Keywords: nntp digest newsgate
Message-ID: <1472@gould.doc.ic.ac.uk>
Date: 22 Jan 90 20:22:25 GMT
References: <6062@cps3xx.UUCP>
Sender: news@doc.ic.ac.uk
Reply-To: dds@cc.ic.ac.uk (Diomidis Spinellis)
Followup-To: news.sysadmin comp.sources.d
Organization: Imperial College Department of Computing
Lines: 174
Content-Length: 5471
In article <6062@cps3xx.UUCP> pantz@mth.msu.edu (Tzu-Hsi Pan) writes:
>
>I'm interested in setting up a bridge such that mailing list members
>can receive news from a particular USENET news group and they can also
>post news to USENET thru the bridge.

The following script provides the USENET to mailing list function.  It
connects to a host running nntp and automatically creates a digest of
all articles that appeared in the newsgroup since the last time it was
run together with instructions to forward it to a list.  Change the
actual script in order to configure it for your needs.  The output of
the script needs to be piped to sh, so you will probably run it with a
crontab entry like:

30 03 * * * /usr/local/bin/newsgate | sh

There must be more comprehensive and sophisticated programs available.
This script however works and is very easy to configure.  There is a 
feature for adding articles local to the digest.  The whole script needs 
named pipes.

Diomidis

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	newsgate
# This archive created: Mon Jan 22 20:18:55 1990
export PATH; PATH=/bin:$PATH
echo shar: extracting "'newsgate'" '(3209 characters)'
if test -f 'newsgate'
then
	echo shar: will not over-write existing file "'newsgate'"
else
sed 's/^X//' << \SHAR_EOF > 'newsgate'
X#!/bin/sh
X# Create a news digest from a newsgroups list using an nntp server.
X# The output of the command can be fed to sh to mail the digest off.
X#
X# (C) Copyright 1989 Diomidis Spinellis.  All rights reserved.
X#
X# Redistribution and use in source and binary forms are permitted
X# provided that the above copyright notice and this paragraph are
X# duplicated in all such forms.
X# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X
XNEWSGATESPOOL=/usr/local/spool/digest
X# The nntp host
XHOST=uunet.uu.net
X
X# Groups to digest
XGROUPS="comp.sources.unix comp.sources.misc alt.sources"
X
X# Where the numbers of the last articles forwarded are kept
XLAST=$NEWSGATESPOOL/last
X
X# Local messages.  Automatically erased after used.
X# Each local article must be terminated with 78i- (A line of 78 -)
XLOCAL=$NEWSGATESPOOL/local
X
X# Digest number
XNUMBERFILE=$NEWSGATESPOOL/nf
XNUMBER=`cat $NUMBERFILE 2>/dev/null || echo 1`
X
X# People who receive the digest. Must be comma separated.
XRECEIVERS='user1@foo.bar, user2@bar.foo, user3@foo.bar,
X	user4, user5@foobar'
XSRECEIVERS=`echo $RECEIVERS | sed -e 's/,//g'`
X
X# We need this so that telnet does not see a file close.
Xrm -f cmds cmds1
X/usr/etc/mknod cmds p
X/usr/etc/mknod cmds1 p
X
X# Ask for the articles available in the groups we are interested in
X(
X	for i in $GROUPS 
X	do
X		echo group $i
X	done
X	echo quit
X) >cmds &
X# Feed nntp with them and create nntp commands to print each article
X(
X	# This is the list of articles already used.  They are refixed by HHH
X	cat $LAST  2>/dev/null ||
X	# If file does not exist initialise to 0
X	for i in $GROUPS 
X	do
X		echo "HHH $i 0"
X	done
X	# Make it zero longth so we can append the new ones
X	cp /dev/null $LAST
X	# This will print the available articles prefixed by 211
X	telnet gould nntp <cmds 2>/dev/null
X) |
X/bin/awk '
X# Already sent
X/^HHH/	{ 
X	last[$2] = $3 
X}
X# Articles available
X/^211/	{
X	if (last[$5] > $3)
X		first = last[$5] + 1
X	else
X		first = $3
X	print "group", $5
X	for (i = first; i < $4; i++)
X		print "article", i
X	# Update the last file
X	print "HHH", $5, $4 >>"'$LAST'"
X}
XEND	{
X	print "quit"
X}
X' >cmds1 &
X
X# Now get the articles and create the batch
Xtelnet gould nntp <cmds1 2>/dev/null |
Xsed -n -e '
X# Do not print anything that comes of telnet after connection is closed
X/^205.*closing connection\.  Goodbye\.$/q
X# Print only some items from the header
X/^220.*Article retrieved; head and body follow\.$/,/^$/ {
X	/^From/p
X	/^Subject/p
X	/^Date/p
X	/^Newsgroups/p
X}
X# Print all the body
X/^$/,/^\./p
X' |
X(
Xcat <<EOF
X#!/bin/sh
X/usr/lib/sendmail -i "$SRECEIVERS" <<\END_SOURCES
XDate: `date`
XTo: $RECEIVERS
XFrom: Source Digest <source@foo.bar>
XSubject: The Source Groups Digest $NUMBER
X
XThis digest contains all articles posted in the USENET newsgroups
Xcomp.sources.misc, comp.sources.unix and alt.sources.
X
X------------------------------------------------------------------------------
X`cat $LOCAL`
X
XEOF
Xsed -e 's/^\./------------------------------------------------------------------------------/'
Xecho END_SOURCES
X)
X
Xexpr $NUMBER + 1 >$NUMBERFILE
Xrm -f cmds cmds1
Xcp /dev/null $LOCAL
SHAR_EOF
if test 3209 -ne "`wc -c < 'newsgate'`"
then
	echo shar: error transmitting "'newsgate'" '(should have been 3209 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0

--
Diomidis Spinellis                  Internet:                 dds@cc.ic.ac.uk
Department of Computing             BITNET:                   dds@cc.ic.ac.uk
Imperial College                    UUCP:   ...!cernvax!cc.imperial.ac.uk!dds
London SW7 2BZ                      JANET:                    dds@uk.ac.ic.cc



Newsgroup news.sysadmin contents
Newsgroup list
Diomidis Spinellis home page

Creative Commons License Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.