wildcards
authorheiko
Wed, 03 Jan 2007 10:17:54 +0000
changeset 25 de6564667c1b
parent 24 93551b0dbeee
child 26 57fb725ce549
wildcards
debian/cron.daily
exigrey.pl
--- a/debian/cron.daily	Wed Jan 03 09:36:10 2007 +0000
+++ b/debian/cron.daily	Wed Jan 03 10:17:54 2007 +0000
@@ -1,2 +1,2 @@
 #! /bin/bash
-exigrey --clean 3 `exigrey --dbs` >/dev/null
+exigrey --clean 3 '*'
--- a/exigrey.pl	Wed Jan 03 09:36:10 2007 +0000
+++ b/exigrey.pl	Wed Jan 03 10:17:54 2007 +0000
@@ -10,7 +10,7 @@
        !ME! --list [db]			# list all items
        !ME! --stat [db ...]		# print short statistic
        !ME! --clean [days [db ...]]	# remove items not used since <days> days
-       !ME! --dbs			# list dbm files in default directory
+       !ME! --dbs [glob]		# list dbm files in default directory
 
        Defaults: delay: !$DEFAULT{delay}!
 		 db:    !$DEFAULT{db}!
@@ -39,6 +39,7 @@
 my $opt_clean;
 my $opt_dbs;
 
+sub getDBs($);
 sub iterate(\%$);
 
 MAIN: {
@@ -72,7 +73,9 @@
     }
 
     if ($opt_stats) {
-	foreach ((@ARGV ? @ARGV : $DEFAULT{db})) {
+	@ARGV = ($DEFAULT{db}) unless @ARGV;
+	@ARGV = getDBs($ARGV[0]) if $ARGV[0] =~ /[\*\?]/;
+	foreach (@ARGV) {
 	    my %h;
 	    my $db = connectDB(\%h, $_);
 
@@ -107,6 +110,8 @@
 
     if ($opt_clean) {
 	my $cut = time() - (86400 * (@ARGV ? shift : 7));
+	@ARGV = ($DEFAULT{db}) unless @ARGV;
+	@ARGV = getDBs($ARGV[0]) if $ARGV[0] =~ /[\*\?]/;
 	foreach (@ARGV ? @ARGV : $DEFAULT{db}) {
 	    my %h;
 	    my $tmp = tmpfile();
@@ -126,7 +131,7 @@
     }
 
     if ($opt_dbs) {
-	print join("\n", glob(getDBDir() . "/*")), "\n";
+	print join("\n", getDBs(shift || "*")), "\n";
 	exit 0;
     }
 
@@ -136,6 +141,10 @@
     }
 }
 
+sub getDBs($) {
+    glob(getDBDir() . "/$_[0]");
+}
+
 # Helper to iterate over our hash and call the passed
 # "callback" function (item, v0, v1, delta)
 sub iterate(\%$) {