Article View: news.software.nntp
Article #12398Re: Merging newsgroups & active..?
From: Mail account for root
Date: Sun, 17 Nov 1996 00:00
Date: Sun, 17 Nov 1996 00:00
237 lines
8586 bytes
8586 bytes
Robert S. Liesenfeld <xunil@bitstream.net> wrote:
: Hi there.
: I'm the poor schmuck who's stuck with maintaining INN at our site; we get
: news feeds from two different places, and we have a couple of local
: newsgroups. Both of our newsfeeds just added (doubled, actually) some
: newsgroups. I am now assigned the task of merging the actives and
: newsgroups from visi.com and mr.net with our own. What's the best way to
: do this? I've already tried a hopeless attempt involving cat, sort, uniq,
: and pipes...=] Please help!
: Please reply via email to xunil@bitstream.net; any and all help is
: appreciated. Thanks in advance!
: -R
: -----------------------------------------------------------------------
: Robert S. Liesenfeld <>< | Mail/News/UUCP Administrator
: xunil@bitstream.net IRC:Xunil | Programmer
: http://www2.bitstream.net/~xunil/ | Network Engineer
: finger for PGP public key | Die-hard Linux Addict
: "Fnord." | Bitstream Underground, Mpls, MN
Here is what I use (feel free to adapt it in any way you want, the script
and the new "active" and "newsgroups" must in in a subdirectory of ~news):
#!/usr/bin/perl
#
# @(#) merge.pl - Merge either active or newsgroups
# The newest files can be obtained from ftp://ftp.uu.net/news/config
#
# (c) Copyright 1996 Thomas Bullinger
#
# 1.00 21-May-1996 TB First version
# 1.10 22-May-1996 TB Added newsgroups
# 1.11 27-Oct-1996 TB Allow serial -a and -n
# Constants
($ProgName = $0) =~ s%.*/%%;
$Version = "1.11 (27-Oct-1996)";
$CopyRight = "(c) Copyright 1996 Thomas Bullinger";
# Some programs
$Copy = "/bin/cp";
$ChOwn = "/bin/chown";
$CtlInnd = "../bin/ctlinnd";
# The files we work on
$ActiveNow = "../active";
$ActiveNew = "./active";
$SortedActive = "./active.sorted";
$SortedActiveNew = "./active.new";
$NGNow = "../newsgroups";
$NGNew = "./newsgroups";
$SortedNG = "./newsgroups.sorted";
$SortedNGNew = "./newsgroups.new";
require 'getopts.pl';
###########################################################
# Display the usage
###########################################################
sub ShowUsage {
print "Usage: $ProgName [options]\n",
" -a Process \"active\"\n",
" -n Process \"newsgroups\"\n",
" -v Be verbose\n",
" -h Show this help\n";
exit 0;
} # end ShowUsage
###########################################################
# Main function
###########################################################
print ("$ProgName, Version $Version\n$CopyRight\n\n");
# Get possible options
&Getopts ('anhv') || &ShowUsage;
&ShowUsage if (($opt_h) || ((! $opt_a) && (! $opt_n)));
# Make stdout unbuffered
$| = 1;
if ($opt_a) {
# Open a connection to the sort program
open (ST, "| sort -u > $SortedActive") || die "ERROR: Can not find sort\n";
print "Sorting active.\n" if ($opt_v);
# Get the current active file
open (AF, "$ActiveNow") || die "ERROR: $ActiveNow not found\n";
print "Reading \"$ActiveNow\"..." if ($opt_v);
while ($Entry = <AF>) {
($NewsGroup, $MinE, $MaxE, $NFlag) = split (/ /, $Entry);
chomp ($CurrentActive{$NewsGroup} = "$MinE $MaxE $NFlag");
print ST "$NewsGroup\n";
}
close (AF);
print " done.\n" if ($opt_v);
# Get the new active file
open (AF, "$ActiveNew") || die "ERROR: $ActiveNew not found\n";
print "Reading \"$ActiveNew\"..." if ($opt_v);
while ($Entry = <AF>) {
($NewsGroup, $MinE, $MaxE, $NFlag) = split (/ /, $Entry);
chomp ($NewActive{$NewsGroup} = "$MinE $MaxE $NFlag");
print ST "$NewsGroup\n";
}
close (AF);
print " done.\n" if ($opt_v);
close (ST);
print "Sorting done.\n" if ($opt_v);
# Get the sorted active file
open (AF, "$SortedActive") || die "ERROR: $SortedActive not found\n";
open (SN, "> $SortedActiveNew") || die "ERROR: Can not create $SortedActiveNew\n";
print "Transforming \"$SortedActive\" to \"$SortedActiveNew\".\n" if ($opt_v);
$EntryNum = 0;
while ($Entry = <AF>) {
chomp ($Entry);
print "Newsgroup: $Entry\n" if ($opt_v);
# Is the entry in the current active ?
if ( $CurrentActive{$Entry}) {
# Yes -> keep it
print SN "$Entry $CurrentActive{$Entry}\n";
} else {
# No -> Keep the new one
print SN "$Entry $NewActive{$Entry}\n";
}
$EntryNum++;
} # end while
close (AF);
close (SN);
unlink ($SortedActive);
print "Transformation done ($EntryNum entries).\n" if ($opt_v);
# Reload the active file
print "Reloading updated active..." if (opt_v);
system ("$CtlInnd pause Reloading active");
system ("$Copy $SortedActiveNew $ActiveNow");
system ("$ChOwn news.news $ActiveNow");
system ("$CtlInnd reload active Upgraded by $ProgName");
system ("$CtlInnd go Reloading active");
print "Current server status:\n";
system ("$CtlInnd mode");
print " done.\n" if ($opt_v);
# Some parting words
print "\nIf everything went okay you may delete the following file:\n",
"$SortedActiveNew\n";
}
if ($opt_n) {
# Open a connection to the sort program
open (ST, "| sort -u > $SortedNG") || die "ERROR: Can not find sort\n";
print "Sorting newsgroups.\n" if ($opt_v);
# Get the current active file
open (AF, "$NGNow") || die "ERROR: $NGNow not found\n";
print "Reading \"$NGNow\"..." if ($opt_v);
while ($Entry = <AF>) {
($NewsGroup, $Desc) = split (/\t+/, $Entry);
chomp ($CurrentNG{$NewsGroup} = "$Desc");
print ST "$NewsGroup\n";
}
close (AF);
print " done.\n" if ($opt_v);
# Get the new active file
open (AF, "$NGNew") || die "ERROR: $NGNew not found\n";
print "Reading \"$NGNew\"..." if ($opt_v);
while ($Entry = <AF>) {
($NewsGroup, $Desc) = split (/\t+ /, $Entry);
chomp ($NewNG{$NewsGroup} = "$Desc");
print ST "$NewsGroup\n";
}
close (AF);
print " done.\n" if ($opt_v);
close (ST);
print "Sorting done.\n" if ($opt_v);
# Get the sorted active file
open (AF, "$SortedNG") || die "ERROR: $SortedNG not found\n";
open (SN, "> $SortedNGNew") || die "ERROR: Can not create $SortedNGNew\n";
print "Transforming \"$SortedNG\" to \"$SortedNGNew\".\n" if ($opt_v);
$EntryNum = 0;
while ($Entry = <AF>) {
chomp ($Entry);
print "Newsgroup: $Entry\n" if ($opt_v);
# Is the entry in the current active ?
if ( $CurrentNG{$Entry}) {
# Yes -> keep it
print SN "$Entry $CurrentNG{$Entry}\n";
} else {
# No -> Keep the new one
print SN "$Entry $NewNG{$Entry}\n";
}
$EntryNum++;
} # end while
close (AF);
close (SN);
unlink ($SortedNG);
print "Transformation done ($EntryNum entries).\n" if ($opt_v);
# Reload the active file
print "Reloading updated newsgroups..." if (opt_v);
system ("$Copy $SortedNGNew $NGNow");
system ("$ChOwn news.news $NGNow");
print "Current server status:\n";
system ("$CtlInnd mode");
print " done.\n" if ($opt_v);
# Some parting words
print "\nIf everything went okay you may delete the following file:\n",
"$SortedNGNew\n";
}
exit 0;
--______ __ ---------------------------------------------------------
' / '/ ) Thomas Bullinger
/ /--< This is the mail account for root@btoy1.rochester.ny.us
(_/ /___/ http://btoy1-gw.roc.servtech.com/index.phtml
Technical Details
Message-ID:
<56lqif$fau@btoy3.btoy1.rochester.ny.us>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mailReferences:
<Pine.SOL.3.95.961116145045.8680A-100000@marley>Show Full Headers
Complete Article Headers
Message-ID: <56lqif$fau@btoy3.btoy1.rochester.ny.us> Subject: Re: Merging newsgroups & active..? Date: Sun, 17 Nov 1996 00:00:00 +0000 From: Mail account for root <rootmail@btoy1.rochester.ny.us> References: <Pine.SOL.3.95.961116145045.8680A-100000@marley> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail X-Deja-AN: 196966297 Distribution: inet Content-type: text/plain; charset=US-ASCII Organization: A private site Mime-version: 1.0 Reply-to: rootmail@btoy1.rochester.ny.us Newsgroups: news.software.nntp