Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

clearing 2k eventlog

by RayRay459 (Pilgrim)
on Dec 21, 2001 at 22:44 UTC ( [id://133835]=perlquestion: print w/replies, xml ) Need Help??

RayRay459 has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks, i am in need of your assistance. I am trying to use perl to clear the event log on NT4 and 2k machines. I am having no such luck. Here is the code that i have. Can anyone please help in pointing out what i am doing wrong. I am getting "no such file or directory" when i run this. needless to say, the code so far isn't doing anything.
Thanks in advance
Ray
#!/usr/bin/perl use Win32::EventLog; use strict; my ($Event, $filename, $directory); $directory = 'c:/EventLogs/'; for ('System', 'Security', 'Application') { $Event = new Win32::EventLog ("$_", ""); $filename = $directory . $_ . '.evt'; $Event->Clear($filename)or die "Couldn't clear eventlogs: $!"; }

Replies are listed 'Best First'.
(crazyinsomniac) Re: clearing 2k eventlog
by crazyinsomniac (Prior) on Dec 22, 2001 at 09:32 UTC
    If it's not dying the only thing that comes to mind is that you forgot to close the eventlog, ie: $Event->Close();. Whether or not that happens automatically when $Event goes out of scope, I don't know, but you should call Close either way (being explicit is goood). If that doesn't work, meaning the changes don't get recorded, I sugguest you try upgrading Wil32::EventLog (which version do you have). Also, you might wanna try "Backup" to see if that works.

    update: D'oh! I didn't even notice that error message you gave, "no such file or directory", that was your answer right there ;)

     
    ___crazyinsomniac_______________________________________
    Disclaimer: Don't blame. It came from inside the void

    perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

      I had the path wrong for $directory. here's my working script:
      # Ray Espinoza # eventclear.pl # This will clear the local eventlog to be used in the update.cmd scri +pt for new builds. ###################################################################### +################## #!/usr/bin/perl use Win32::EventLog; use strict; my ($Event, $filename, $directory); $directory = 'c:/temp/'; for ('System', 'Security', 'Application') { $Event = new Win32::EventLog ("$_", "") || die "can't create o +bject\n"; $filename = $directory . $_ . '.evt'; print " $filename exists\n" if (-e "$filename"); $Event->Clear($filename)or warn " $!"; $Event->Close(); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://133835]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-03-28 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found