Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Background

I wrote this to take a list of servers from a text file, and backup their event logs to .evt files in a central location. I am running the script from a Win2000 Server against a mix of 2000 and NT4 servers, and for 80% of them there is no problem.

Problem

  1. For eventlogs over 300MB, the script backs up a 1KB file. When opened, the log file is blank, but will say 1.8 million records. Manual backing up will back up the full 300 MB.
  2. For NT4 Servers, I am getting "Access is Denied" when trying to back up the logs. I can back up the eventlogs manually with the same account used by the script.

What I've Tried

Tried different accounts, waded through activestate mailing lists, upgraded the activestate build from 631 to 633, searched google, begged, pleaded, and sacrificed two goats.

The Code

# Jonathan Dyer X-XXXX, # Written to take input of list of servers in eventlogs_in.txt and bac +kup the # event logs to \\XXXXXXX\EVENTLOGS\SERVER\LOGNAME\DATE use strict; use Win32::EventLog; use File::Copy; open IN, "<//XXXXXXX/c\$/scripts/eventlogs/eventlogs_in.txt"; while (<IN>){ chomp; my $server="$_"; print "\n$server\n"; my($date)=join("-", ((split(/\s+/, scalar(localtime)))[1,2,4])); my $remdir="//XXXXXXX/eventlogs/$server"; open OUT, ">>//XXXXXXX/eventlogs/backuperrors.log" || die "BackupE +rrors.log cannot be written. Stopping."; print OUT "$date\n"; for my $eventlog ("Application", "System", "Security") { print "\t$eventlog"; my $locdir="//$server/c\$/temp/$eventlog"; my $dest="$locdir/$date.evt"; if (!-e $locdir){mkdir ("$locdir") || print OUT "ERR: Can't cr +eate local log directory on $server: ($^E)\n";} if (!-e $remdir){mkdir ("$remdir") || print OUT "ERR: Can't cr +eate $remdir: ($^E)\n";} if (!-e "$remdir/$eventlog"){mkdir ("$remdir/$eventlog") || pr +int OUT "ERR: Can't create $remdir/$eventlog: ($^E)\n";} if ((-e "$remdir/$eventlog")&&(-e "$locdir")){ my %event=( 'Computer',"$server", 'EventID','777', 'EventType',EVENTLOG_INFORMATION_TYPE, 'Category','None', 'Strings',"The $eventlog Event log was backed up to $remdi +r.", 'Data',"The $eventlog Event log was backed up.", ); my $handle=Win32::EventLog->new($eventlog, "\\\\$server") +|| print OUT "ERR: Can't read $eventlog EventLog on $server:($^E)\n"; $handle->Backup($dest) || print OUT "ERR: Could not backup + the $eventlog EventLog on $server to $dest ($^E)\n"; #$handle->Clear($dest) || print OUT "ERR: Could not clear +the $eventlog EventLog on $server:($^E)\n"; $handle->Report(\%event) || print OUT "ERR: Could not writ +e to the $eventlog event log:($^E)\n" unless ($eventlog=="Security"); + #Needed b/c writing to Security log is not allowed $handle->Close; copy($dest,"$remdir/$eventlog/$date.evt") || print OUT "ER +R: Couldn't Copy $eventlog Log on $server from $dest to $remdir/$even +tlog:($!)\n"; #unlink "$dest"; } } print OUT "----------\n"; close OUT; }

Any ideas are welcome. I'm ready to scrap this and go with a co-worker's C-Solution, but it would be a shot to Perl here.

Thanks.

-OzzyOsbourne


In reply to Win32::Eventlog Issues: Access Denied, Incorrect log size by OzzyOsbourne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-19 18:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found