Some options added.
authorheiko
Wed, 03 Jan 2007 09:21:21 +0000
changeset 23 bce276394054
parent 22 91803f1e2741
child 24 93551b0dbeee
Some options added.
exigrey.pl
exim-exigrey.pl
--- a/exigrey.pl	Wed Jan 03 08:55:02 2007 +0000
+++ b/exigrey.pl	Wed Jan 03 09:21:21 2007 +0000
@@ -6,10 +6,11 @@
 
 use constant USAGE => <<'#';
 
-Usage: !ME! item [delay [db]]
-       !ME! --list [db]
-       !ME! --stat [db]
-       !ME! --clean [days [db]]
+Usage: !ME! --insert item [delay [db]]	# insert an item
+       !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
 
        Defaults: delay: !$DEFAULT{delay}!
 		 db:    !$DEFAULT{db}!
@@ -33,8 +34,10 @@
 
 my $opt_list;
 my $opt_stats;
+my $opt_insert;
 my $opt_help;
 my $opt_clean;
+my $opt_dbs;
 
 sub iterate(\%$);
 
@@ -42,8 +45,10 @@
 
     GetOptions(
 	"list!" => \$opt_list,
+	"insert!" => \$opt_insert,
 	"stats!" => \$opt_stats,
 	"clean!" => \$opt_clean,
+	"dbs!" => \$opt_dbs,
 	"help!" => \$opt_help,
     ) or die ME.": Bad usage, try ".ME." --help.\n";
 
@@ -120,7 +125,15 @@
 	exit 0;
     }
 
-    print unseen(@ARGV, 10) . "\n";
+    if ($opt_dbs) {
+	print join("\n", glob(getDBDir() . "/*")), "\n";
+	exit 0;
+    }
+
+    if ($opt_insert) {
+	print unseen(@ARGV);
+	exit 0;
+    }
 }
 
 # Helper to iterate over our hash and call the passed
--- a/exim-exigrey.pl	Wed Jan 03 08:55:02 2007 +0000
+++ b/exim-exigrey.pl	Wed Jan 03 09:21:21 2007 +0000
@@ -104,10 +104,12 @@
     # this file
     if (!-f $db) {
 	(my $dir = $db) =~ s/^(.*)\/.*?$/$1/;
+
 	# copy mode, uid, gid from the directory
 	my ($mode, $user, $group) = (stat $dir)[2,4,5] or die "Can't stat $dir: $!";
 	my $umask = umask(($mode & 0777) ^ 0777);
-	local ($>, $)) = ($user, $group);
+	local $) = $group;
+	local $> = $user;
 	open(X, ">>$db") or die "Can't create $db: $!";
 	close(X);
 	umask $umask;