bklog for INN (fwd)

Bill Davidsen davidsen at tmr.com
Fri Sep 13 15:50:30 UTC 2002


Russ, here's the backlog program I mentioned.

-- 
bill davidsen <davidsen at tmr.com>
  CTO, TMR Associates, Inc
Doing interesting things with little computers since 1979.


-- Attached file included as plaintext by Ecartis --
-- File: bklog

#!/usr/bin/perl
# bklog 1.8 2001-07-23 11:46:54-04 news Prod

# bklog - display backlog to sites
$dir = "/usr/local/news/spool/innfeed";
$Revision = '1.8';

use Getopt::Std;
$| = 1;

# option procession
&getopts("HhntkS:") || &Usage;
&Usage if $opt_h;

# open the directory;
chdir($dir) || die "Can't cd to $dir";
opendir(DIR, ".");
die "Can't open dir" unless defined(DIR);

while ($name = readdir(DIR)) {
	# must be a file, correct name, non-zero size
	next unless -f $name;
	next unless ($size = -s $name);
	next unless $name =~ m/.*\.(in|out)put/;
	$io = $1;
	($nodename = $name) =~ s/\..*//;

	# check for only some sites wanted
	next if ($opt_S && $nodename !~ /^${opt_S}.*/);
	# here we do the counts if asked
	if ($opt_n) {
		# open the file and count lines
		if (open(IN, "<$name")) {
			if ($name =~ m/.*\.input/) {
				$offset = <IN> + 0;
				seek(IN, $offset, 0);
			}
			$size = 0;
			for ($size = 0; <IN> ; ++$size) {};
			close IN;
		}
	} else {
		# get the offset on .input files
		if ($name =~ m/.*\.input/ && open(IN, "<$name")) {
			$offset = <IN> + 0;
			$size -= $offset;
			close IN;
		}
	}			
	$nodes{$nodename} = () unless defined $nodes{$nodename};
	$nodes{$nodename}->{$io} = ( $opt_k ? $size / 1024 : $size );
}
closedir DIR;

# output the data for each node
if ($numnodes = keys %nodes) {
	if ($opt_H) {
		if ($opt_n) {
			print "  <---------- posts ----------->\n";
		} else {
			print "  <---------- bytes ----------->\n";
		}
	}
	if ($opt_k) {
		print "  input(k)  output(k)   total(k) Feed Name\n" if $opt_H;
		$ofmt = ( $opt_n ? "%10.2f" : "%10.1f" );
	} else {
		print "     input     output      total Feed Name\n" if $opt_H;
		$ofmt = "%10d";
	}
	for $node (sort keys %nodes) {
		$hash = $nodes{$node};
		$size_in = $hash->{in};
		$size_out = $hash->{out};
		$size_tot = $size_in + $size_out;
		printf "${ofmt} ${ofmt} ${ofmt} %s\n",
			$size_in, $size_out, $size_tot, $node;
	}
} else {
	print "NO backlog!\n";
}

exit 0;

sub Usage
{
	print "\n"
	. "bklog - print innfeed backlog info - v$Revision\n"
	. "\n"
	. "Format:\n"
	. "  bklog [ options ]\n"
	. "\n"
	. "Options:\n"
	. "  -H     output a header at the top of the output\n"
	. "  -k     scale all numbers in k (1024) units\n"
	. "  -n     count number of arts, not bytes of backlog filesize\n"
	. "         Note: this may be SLOW for large files!\n"
	. "  -Sxx   Display only site names starting with xx\n"
	. "\n"
	. "  -h     HELP - this is all, you got it!\n"
	. "\n";

	exit 1;
}



More information about the inn-patches mailing list