Hello,
I maybe an average joe programmer but do know perl has good text processing support. Now I'd like to go through yesterdays eventlogs and recover some useful information from there (print logs in particular). The Print logs notmally are like "Document Wod.doc owned by DUSASAE was printed on HPLJ5 via port LPT1. Size in bytes: 37836; pages printed: 1"
Now I'd like the pages printed, filename, username on separate fields. Here is the code I used to do it. Most of the cost is copy/paste from various helpfiles and searches on the net.
In the long term I'd just write this info to an Access Db for further reporting, more on that later.
use Win32::EventLog;
$handle=Win32::EventLog->new("System", $ENV{ComputerName})
or die "Can't open Application EventLog\n";
$handle->GetNumber($recs)
or die "Can't get number of EventLog records\n";
$handle->GetOldest($base)
or die "Can't get number of oldest EventLog record\n";
($sec1,$min1,$hour1,$mday1,$mon1,$year1,$wday1,$yday1,$isdst1) = local
+time(time()-86400);
$year1 +=1900;
$mon1++;
print "$mday1 $mon1 $year1\n";
while ($x < $recs) {
$handle->Read(EVENTLOG_FORWARDS_READ|EVENTLOG_SEEK_READ,
$base+$x,
$hashRef)
or die "Can't read EventLog entry #$x\n";
if ($hashRef->{Source} eq "Print") {
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = lo
+caltime($hashRef->{'TimeGenerated'});
$year += 1900;
$mon++;
#print "$mday1 $mday \n";
#if (($mday1 eq $mday)&($mon eq $mon1)&($year eq $year1))
+{
# Win32::EventLog::GetMessageText($hashRef);
# print "Entry $x: $mday $mon $year $hashRef->{Message}
+\n";
# $Message = $hashRef->{Message};
#}
}
$x++;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.