multiple database files für Statistik und Cleaning
authorheiko
Wed, 03 Jan 2007 08:55:02 +0000
changeset 22 91803f1e2741
parent 21 f47d0026ab09
child 23 bce276394054
multiple database files für Statistik und Cleaning
exigrey.pl
--- a/exigrey.pl	Tue Jan 02 23:15:14 2007 +0000
+++ b/exigrey.pl	Wed Jan 03 08:55:02 2007 +0000
@@ -67,54 +67,56 @@
     }
 
     if ($opt_stats) {
-	my %h;
-	my $db = connectDB(\%h, shift || $DEFAULT{db});
-
-	my ($seen, $returned, $oldest);
-	$oldest = time();
-	iterate(%h, sub {
-	    my ($item, $v0, $v1, $dv) = @_;
-	    ++$seen;
-	    ++$returned if $dv;
-	    $oldest = $v0 if $v0 < $oldest;
-	});
+	foreach ((@ARGV ? @ARGV : $DEFAULT{db})) {
+	    my %h;
+	    my $db = connectDB(\%h, $_);
 
-	$_ = <<__;
-        date: %s
-          db: $db (ls: %.1f MB / du: %.1f MB)
-       total: $seen
-not returned: %d (%d%%)
-      oldest: %.1f days (%s)
+	    my ($seen, $returned, $oldest);
+	    $oldest = time();
+	    iterate(%h, sub {
+		my ($item, $v0, $v1, $dv) = @_;
+		++$seen;
+		++$returned if $dv;
+		$oldest = $v0 if $v0 < $oldest;
+	    });
+
+	    $_ = <<__;
+	    date: %s
+	      db: $db (ls: %.1f MB / du: %.1f MB)
+	   total: $seen
+    not returned: %d (%d%%)
+	  oldest: %.1f days (%s)
 __
-	printf $_, 
-		scalar(localtime), 
-		(-s $db) / (1024*1024),
-		((stat $db)[12]*512)/(1024*1024),
-		$seen - $returned, 
-		int(100 * ($seen-$returned)/$seen), 
-		((time - $oldest) / 86400), scalar(localtime $oldest);
+	    printf $_, 
+		    scalar(localtime), 
+		    (-s $db) / (1024*1024),
+		    ((stat $db)[12]*512)/(1024*1024),
+		    $seen - $returned, 
+		    int(100 * ($seen-$returned)/$seen), 
+		    ((time - $oldest) / 86400), scalar(localtime $oldest);
+	    print "\n" if @ARGV;
 
+	}
 	exit 0;
     }
 
     if ($opt_clean) {
-	my %h;
-	my $days = shift; $days = 7 unless defined $days;
-	my $db = shift; $db = $DEFAULT{db} unless defined $db;
-
-	my $cut = time() - ($days * 86400);
-	my $tmp = tmpfile();
+	my $cut = time() - (86400 * (@ARGV ? shift : 7));
+	foreach (@ARGV ? @ARGV : $DEFAULT{db}) {
+	    my %h;
+	    my $tmp = tmpfile();
+	    my $db = connectDB(\%h, $_);
+	    iterate(%h, sub {
+		my ($item, $v0, $v1, $dv) = @_;
+		print $tmp $item if $v1 <= $cut;
+	    });
 
-	$db = connectDB(\%h, $db);
-	iterate(%h, sub {
-	    my ($item, $v0, $v1, $dv) = @_;
-	    print $tmp $item if $v1 <= $cut;
-	});
+	    seek($tmp, 0, 0) or die "Can't seek tmpfile";
+	    delete $h{$_} while <$tmp>;
+	    close($tmp);
 
-	seek($tmp, 0, 0) or die "Can't seek tmpfile";
-	delete $h{$_} while <$tmp>;
-
-	print "$. items deleted\n";
+	    print "$. items deleted from $db\n";
+	}
 	exit 0;
     }