File: logreport1.pl

package info (click to toggle)
emboss 6.6.0%2Bdfsg-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 571,584 kB
  • sloc: ansic: 460,579; java: 29,383; perl: 13,573; sh: 12,753; makefile: 3,294; csh: 706; asm: 351; xml: 239; pascal: 237; modula3: 8
file content (31 lines) | stat: -rwxr-xr-x 980 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/perl -w

%progcount=();
%proguser=();

while (<>) {
  chomp;
  if (!/^(\S+)\s+(\S+)\s+(... ... .. ..:..:.. [12][0-9][0-9][0-9])$/) {
    print STDERR "bad logfile line: '$_'\n";
    next;
  }
  $progname = $1;
  $username = $2;
###  $date = $3;
  $progcount{$progname}++;
  $proguser{$progname}{$username}++;
}

print "Program            Total        Username    Total  Pcnt    Other Users\n";
print "=======            =====        ========    =====  ====    ===== =====\n";
 foreach $prog (sort { $progcount{$b} <=> $progcount{$a} } keys (%progcount)) {
  $totuser=0;
  foreach $user (sort { $proguser{$prog}{$a} <=> $proguser{$prog}{$b} } keys (%{$proguser{$prog}})) {
    $maxcount = $proguser{$prog}{$user};
    $maxuser = $user;
    $totuser++;
  }
  $percent = 100.0 * $maxcount/$progcount{$prog};
  $rest = $progcount{$prog} - $maxcount;
  printf "%-15s %8d %15s %8d %5.1f %8d %5d\n", $prog, $progcount{$prog}, $maxuser, $maxcount, $percent, $rest, $totuser;
}