🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
1 messages
1 total messages Started by Paul Close Thu, 15 Aug 1996 00:00
Utility to report top 'n' newsgroup disk hogs
#10138
Author: Paul Close
Date: Thu, 15 Aug 1996 00:00
164 lines
5771 bytes
Here is a nifty perl script I wrote to report the top 'n' largest
newsgroups, as measured by space consumed of your spool directory.
It uses the info in your overview files, which is about 10x faster than
statting all the files in your spool directory.  Note, if you don't
have .overview files stored separately, this may not be as big a win....
You should really keep .overview files separate though.

This script should work fine under either perl4 or perl5.  By default,
it will search your entire overview tree and report the top 15 newsgroups
by size.  You can specify how many to report using -top 'n', and you can
also give it an absolute path to search instead of your overview tree.
It still ignores all files except your overview files, so point it at
the right place :-)

To install, put topten.overview in samples, then go to site and apply the
Makefile patch I've included.  Then type make install (still under site).

I'm really sorry I couldn't 'shar' this, but I have a new system, and
haven't gotten around to finding and building shar.

First is the site/Makefile patch:

----------------------------------------

*** Makefile.old	Thu Aug 15 13:14:51 1996
--- Makefile	Thu Aug 15 13:15:37 1996
***************
*** 60,66 ****
  	nntpsend send-ihave \
  	    send-nntp send-uucp sendbatch \
  	ctlrun inncheck innstat \
! 	    innwatch innlog.awk innshellvars
  MOST_INSTALLED	= \
  	$(NEWSBIN)/makegroup $(PATH_NEWSBOOT) $(PATH_SCHEMA) \
  	$(CTLBIN)/checkgroups $(CTLBIN)/default $(CTLBIN)/ihave \
--- 60,67 ----
  	nntpsend send-ihave \
  	    send-nntp send-uucp sendbatch \
  	ctlrun inncheck innstat \
! 	    innwatch innlog.awk innshellvars \
! 	topten.overview
  MOST_INSTALLED	= \
  	$(NEWSBIN)/makegroup $(PATH_NEWSBOOT) $(PATH_SCHEMA) \
  	$(CTLBIN)/checkgroups $(CTLBIN)/default $(CTLBIN)/ihave \
***************
*** 72,78 ****
  	$(NEWSBIN)/nntpsend $(NEWSLIB)/send-ihave \
  	    $(NEWSLIB)/send-nntp $(NEWSLIB)/send-uucp $(NEWSBIN)/sendbatch \
  	$(NEWSBIN)/ctlrun $(NEWSBIN)/inncheck $(NEWSBIN)/innstat \
! 	    $(NEWSBIN)/innwatch $(NEWSLIB)/innlog.awk $(PATH_SHELLVARS)
  
  ##  Scripts from above, plus site-specific config files.
  REST		= \
--- 73,80 ----
  	$(NEWSBIN)/nntpsend $(NEWSLIB)/send-ihave \
  	    $(NEWSLIB)/send-nntp $(NEWSLIB)/send-uucp $(NEWSBIN)/sendbatch \
  	$(NEWSBIN)/ctlrun $(NEWSBIN)/inncheck $(NEWSBIN)/innstat \
! 	    $(NEWSBIN)/innwatch $(NEWSLIB)/innlog.awk $(PATH_SHELLVARS) \
! 	$(NEWSBIN)/topten.overview
  
  ##  Scripts from above, plus site-specific config files.
  REST		= \
***************
*** 190,195 ****
--- 192,198 ----
  $(NEWSBIN)/innwatch:	innwatch	; $(COPY_XPRI) $? $@
  $(PATH_SHELLVARS):	innshellvars	; $(COPY_RPRI) $? $@
  $(NEWSLIB)/innlog.awk:	innlog.awk	; $(COPY_RPRI) $? $@
+ $(NEWSBIN)/topten.overview: topten.overview ; $(COPY_XPUB) $? $@
  
  REASON	= 'Installing site config files from site/Makefile'
  go pause:
***************
*** 245,250 ****
--- 248,254 ----
  senduuname:	../samples/senduuname		; $(COPY) $? $@
  tally.control:	../samples/tally.control	; $(COPY) $? $@
  tally.unwanted:	../samples/tally.unwanted	; $(COPY) $? $@
+ topten.overview: ../samples/topten.overview	; $(COPY) $? $@
  version:	../samples/version		; $(COPY) $? $@
  
  ##  Dependencies.  Default list, below, is probably good enough.

---------- samples/topten.overview -------------

#!/usr/local/bin/perl

# INSTALLATION: subst -f config.data topten.overview.pl

# =()<$ovdir = '@<_PATH_OVERVIEWDIR>@';>()=
die "You did not run subst -f config.data $0. Exiting\n";
# =()<$ovfilename = '@<_PATH_OVERVIEW>@';>()=
$ovfilename = '.overview';

$top = 15;	# really top 15 :)

while ($ARGV[0] =~ m/^(-.*)/ && shift) {
    if ($1 eq '-top') {
	$top = int(shift);
    }
}

# scan overview directory by default

$topdir = shift || $ovdir;

chdir($topdir) || die "Can't cd to $topdir: $!\n";
($topdev) = stat($topdir);

$topdir =~ s,/$,, ;
&finddir($topdir);

@topdir = sort {$dirtotal{$b} <=> $dirtotal{$a}} keys %dirtotal;

print "Top $top newsgroups (kbytes)\n";
for ($i = 0; $i < $top; $i++) {
    last if !defined($topdir[$i]);
    printf "%5d   %s\n", ($dirtotal{$topdir[$i]}+1023)/1024, $topdir[$i];
}

exit(0);

sub finddir {
    local($dir) = @_;
    local($name);

    # Get the list of files in the current directory.

    opendir(DIR,'.') || (warn "Can't open $dir: $!\n", return);
    local(@filenames) = readdir(DIR);
    closedir(DIR);

    for (@filenames) {
	next if $_ eq '.';
	next if $_ eq '..';
	$name = "$dir/$_";
	@stat = lstat($_);
	if (-f _) {
	    next unless $_ eq $ovfilename;
	    ($ngname = $dir) =~ s,^$ovdir/,,o;
	    $ngname =~ s,/,.,g;
	    open (OV, "<$_") || die "Can't open $name: $!\n";
	    while (<OV>) {
		@F=split(/\t/);
		$dirtotal{$ngname} += $F[6];
	    }
	    close(OV);
	}
	elsif (-d _ && $stat[0] == $topdev) {
	    if (chdir $_) {
		&finddir($name);
		chdir '..';
	    }
	}
    }
}

----------------------------------------
-- 
Paul Close		http://reality.sgi.com/pdc (moving soon)
pdc@netcontents.com

Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads