17 # This should be fixed...
22 print "Usage: $0 --file=<counter filename> [--reset=<seconds>] [--match=<regexp>]\n";
23 print "[--user=<username>] [--help] [--hours|--minutes|--seconds]\n\n";
24 print "--user=<username>", "\t\t", "Information for specific user\n";
25 print "--file=<filename>", "\t\t", "Counter db filename\n";
26 print "--match=<regexp>", "\t\t", "Information for matching users\n";
27 print "--reset=<number>", "\t\t", "Reset counter to <number>.\n";
28 print "\t\t\t\t", "If divisor is set use it, else <number> means seconds\n";
29 print "--help", "\t\t\t\t", "Show this help screen\n";
30 print "--(hours|minutes|seconds)", "\t", "Specify information divisor\n";
35 # Print out only one user,
37 # Or specifiy printing in hours, minutes, or seconds (default)
39 GetOptions ('user=s' => \$user,
41 'file=s' => \$filename,
44 'hours' => sub { $divisor = 3600 },
45 'minutes' => sub { $divisor = 60 },
46 'seconds' => sub { $divisor = 1 } );
48 show_help if ($help || $filename eq '');
54 my $db = tie(%hash, 'GDBM_File', $filename, O_RDWR, 0666) or die "Cannot open $filename: $!\n";
56 my $db = tie(%hash, 'GDBM_File', $filename, O_RDONLY, 0666) or die "Cannot open $filename: $!\n";
60 # If given one name, give the seconds
63 if (defined($hash{$user})){
64 print $user, "\t\t", int ( unpack('L',$hash{$user}) / $divisor), "\n";
66 my $uniqueid = (unpack('L A32',$hash{$user}))[1];
67 $hash{$user} = pack('L A32',$reset * $divisor,$uniqueid);
68 print $user, "\t\t", "Counter reset to ", $reset * $divisor, "\n";
71 print $user, "\t\t", "Not found\n";
80 # This may be faster, but unordered.
81 #while (($key,$val) = each %hash) {
83 foreach $key (sort keys %hash) {
86 next if ($key eq "DEFAULT1");
87 next if ($key eq "DEFAULT2");
90 # Allow user names matching a regex.
92 next if ($key !~ /$match/);
95 # Print out the names...
96 print $key, "\t\t", int ( unpack('L',$hash{$key}) / $divisor), "\n";
98 my $uniqueid = (unpack('L A32',$hash{$key}))[1];
99 $hash{$key} = pack('L A32',$reset * $divisor,$uniqueid);
100 print $key, "\t\t", "Counter reset to ", $reset * $divisor, "\n";