#!/usr/local/bin/perl # # mrgdesc Version 1.0 - By Chris Candreva # Stardate 0810.95 # # Script to update the newsgroups file: # 1) merge system newsgroups file with a new one (ie: from another site or # from feed site) if a ./newsgroups file exists. # 2) Add dummy record for any groups in active without a description. # 3) Delete newsgroups record for any group in in active #Modify to point to your active file. $active = "/usr/local/news/active"; # Read first file. # Modify to point to your newsgroups file. open (IN,"/usr/local/news/newsgroups") || die "Can't open newsgroups"; while () { chop; ($n,$d) = split(/[ \011]/,$_,2); # remove leading/trailing space & tabs $d =~ s/\011//g; $newsgroups{$n} = $d; } close IN; # Now merge with second file if ( -e "./newsgroups") { open (IN,"./newsgroups"); while () { chop; ($n,$d) = split(/[ \011]/,$_,2); # remove leading/trailing space & tabs $d =~ s/^[ \011]|[ \011]$//g; #If it's unknown too, don't do anything. if ($d =~ /^\?/) { next; } if ( defined $newsgroups{$n} ) { if ($newsgroups{$n} =~ /^\?|^No Description Available \(yet\)/ ) { print "Change: $n $d\n"; $newsgroups{$n} = $d; } } else { $newsgroups{$n} = $d; print "Add: $n $d\n"; } } close IN; } print "\nNew Groups Added w/o Descriptions:\n"; print "----------------------------------\n"; open (IN,$active); while() { chop; ($n) = split(/ /); #if ($n =~ /comp.infosystems.www.servers.misc/ ) {print "GOT IT!\n";} $active{$n} = 1; unless ( defined $newsgroups{$n} ) { $newsgroups{$n} = "No Description Available (yet)."; print "$n\n"; } } close IN; # Print Output open (OUT,">newsgroups.new"); print "Deleted:\n"; foreach $key (sort(keys %newsgroups)) { unless (defined $active{$key}) {print "$key\n"; next;} $l = length($key); if ($l < 8) {$t = " ";} #3 elsif ($l < 16) {$t = " ";} #2 else {$t = " ";} #1 print OUT "$key$t$newsgroups{$key}\n"; }