Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!ads.com!dglo From: dglo@ADS.COM (Dave Glowacki) Newsgroups: news.software.b Subject: Re: Automatic updating of $NEWSCTL/moderators Message-ID: Date: 12 Apr 91 17:36:50 GMT References: <1991Apr9.153347.9797@uai.com> <1991Apr9.171428.12907@zoo.toronto.edu> <3322@crdos1.crd.ge.COM> Sender: usenet@ads.com (USENET News) Organization: Advanced Decision Systems, Mtn. View, CA (415) 960-7300 Lines: 154 In article <3322@crdos1.crd.ge.COM> davidsen@crdos1.crd.ge.com (bill davidsen) writes: > What I do is to store the posting, then have cron run a makefile which >runs the script, saves the corrected form, and builds the new mailpaths >file from the various parts, some of which are local groups, like the >starix and capdist hierarchies. You don't even need the cron job. This perl script is run from ~news/sys on every article received in news.lists. It creates a mailpaths file *and*, as a special bonus, a file suitable for inclusion in a sendmail aliases file. #!/usr/local/bin/perl # # Extract a list of mail addresses for moderated newsgroups # from the monthly posting in news.lists. # Combine this list with any addresses for local moderated # groups to build the C news 'mailpaths' file. # # To install: # 1) Check the MODALIASES, LOCALALIASES, BASEMAILPATHS and MAILPATHS variables # to make sure they're correct. # 2) Install this someplace where it can be run by news. # 3) Add a line like this to your ~news/sys file (this line works in C news.) # # MODALIAS:world,usa,ca,ba,ads,local,news.lists:\ # m:/some/place/build-mailpaths # # $Header: /var/news/src/ADS-scripts/RCS/build-mailpaths,v 1.5 1991/03/07 19:14:35 dglo Exp $ # subroutine to read in the C news environment # $NEWSCONFIG='/usr/lib/news/bin/config'; %NEWSENV = (); sub newsconfig { if (open(NEWSENV, "sh -x $NEWSCONFIG 2>&1 |")) { while () { $NEWSENV{$1} = $2 if (/(.*)=(.*)\n/); } close(NEWSENV); 1; } else { 0; } } # News locations (handle both C news and B news) # if (&newsconfig()) { $NEWSARTS = $NEWSENV{'NEWSARTS'}; $NEWSCTL = $NEWSENV{'NEWSCTL'}; } else { $NEWSARTS='/usr/spool/news'; $NEWSCTL='/usr/lib/news'; } $MODALIASES = "$NEWSCTL/moderated-aliases"; $LOCALALIASES = "$NEWSCTL/local-moderated-aliases"; $BASEMAILPATHS = "$NEWSCTL/base-mailpaths"; $MAILPATHS = "$NEWSCTL/mailpaths"; # see if the result is supposed to be mailed somewhere # $maillist = ''; while (@ARGV > 0) { $_ = pop(ARGV); $maillist .= ' ' . $_; } # either write to a temp file (to be possibly mailed) or to STDOUT # if ($maillist) { $tmpfile = "/tmp/mperrs.$$"; open(TMPFILE, ">$tmpfile") || die "Can't open a temporary file!\n"; } else { open(TMPFILE, ">-") || die "Couldn't send output to STDOUT!\n"; select(TMPFILE); $| = 1; select(STDOUT); } # only process updated list of moderators # while (<>) { chop; exit if (/^$/); last if (/^Subject: List of Moderators/); } # skip everything until the :------- line # $_ = <> until ((/^:--/) || eof()); exit if (eof()); # process all the moderated list aliases # if (!open(MODFILE, ">$MODALIASES")) { print TMPFILE "Couldn't write to '$MODALIASES'!\n"; } else { while (<>) { chop; last if (/^$/); ($alias,$address) = split; $alias =~ s/\./-/g; print MODFILE $alias,":\t",$address,"\n"; } close(MODFILE); # get rid of the last backup mailpaths file # if ( -f "$MAILPATHS.old" ) { $i = unlink "$MAILPATHS.old"; print TMPFILE "Couldn't unlink '$MAILPATHS.old'!\n" if ($i < 1); } # backup the current mailpaths file # print TMPFILE "Couldn't backup '$MAILPATHS'!\n" if (! rename($MAILPATHS, "$MAILPATHS.old")); if (! open(MAILPATHS, ">$MAILPATHS")) { print TMPFILE "Couldn't create new '$MAILPATHS'!\n"; } else { &catmailpaths($MODALIASES); &catmailpaths($LOCALALIASES); &catmailpaths($BASEMAILPATHS); close(MAILPATHS); } } sub catmailpaths { local($filename) = @_; if ( -f $filename ) { if (! open(FILE, $filename)) { print TMPFILE "Couldn't read '$filename'!\n"; } else { while () { print MAILPATHS $_; } close(FILE); } } } # mail the report (if there's something to mail) # if ($maillist) { system "Mail -s 'build-mailpaths errors' $maillist < $tmpfile" if ( -s $tmpfile ); unlink $tmpfile; } exit 0; -- Dave Glowacki dglo@ads.com Advanced Decision Systems