Audit Windows Print Logs with Perl

I’ve had this script floating around for a while. It can take a CSV export of your event log from a Windows machine, and give you a per-user breakdown of print jobs and pages printed, by date.

[sourcecode language='php']

$date = $ARGV[0];
$file = $ARGV[1];

$totalpages = 0;
@uniq = ();
%seen = ();
%pgs = ();

open(SRC, "<$file") or die("User Error: $!\n");

while () {
  @line = split(',',$_);
  if (($line[0] eq $date) and ($line[5] == 10)) {
    @pages = split('pages printed: ', $_);
    # 3 chops to remove CR, LF, and DQ
    $totalpages = $totalpages + $pages[1];
    push(@uniq, $line[6]) unless $seen{$line[6]}++;
    push(@uniq, $line[6]) unless $pgs{$line[6]}+=$pages[1];


print "Total pages printed: $totalpages\n";

foreach $k (sort keys %seen) {
  print "$k: $seen{$k} jobs, $pgs{$k} pages\n";

Run the script as follows:

perl 12/04/08 eventlog.csv

Back to Top