Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

bootlog.txt shrinker

by dmckee (Scribe)
on Mar 09, 2001 at 00:59 UTC ( #63098=sourcecode: print w/ replies, xml ) Need Help??

Category: Win32 Stuff
Author/Contact Info Dave McKee, dmckee, anti@anti.co.uk
Description: Parses C:\bootlog.txt on Windows 98 machines to extract 'important' lines - ie: the ones where it's all gone wrong. Dead simple
#!/usr/bin/perl -w
use strict;
my ($readline,$found);
my @aok=("Loading Vxd =",             # A list of all the different va
+lues
      "LoadSuccess =",                # that should be ignored. Others
+ are
      "Loading Device =",             # left in for debugging purposes
+.
      "LoadSuccess    =",
      "SYSCRITINIT  =",
      "SYSCRITINITSUCCESS  =",
      "DEVICEINIT   =",
      "DEVICEINITSUCCESS   =",
      "Dynamic init device ",
      "Dynamic init success",
      "Dynamic load device ",
      "Dynamic load success",
      "Initing",
      "Init Success",
      "INITCOMPLETE =",
      "INITCOMPLETESUCCESS =",
      "LoadStart =",
      "Init =",
      "InitDone =",
      "Status =");
open BOOTLOG, "<C:\\bootlog.txt" or die ("Error: could not open c:\\bo
+otlog.txt\n$!\n"); # Open up the file
while (not eof(BOOTLOG)) {
  $readline=<BOOTLOG>;
  $found=0;
  foreach (@aok) {if ($readline =~ m/.*$_.*/) {$found=1}}; # Check aga
+inst each @aok to see if it's valid: if it is, $found.
  chomp($readline);                                        # If not, t
+hen print it out if it's not just a newline.
  unless ($found) {if ($readline) {print "$readline\n";}};
}

Comment on bootlog.txt shrinker
Download Code
Re: bootlog.txt shrinker
by a (Friar) on Mar 09, 2001 at 10:25 UTC
    Nice. Always wondered what was important in that file, however a couple of things: seems like you're doing more work than needed (why the "not eof( ..." as opposed to
    while ($readline = <BOOTLOG>)
    but then I ended up needing the $readline to get your exact output.) and going through the entire @aok each line is slower. I thought a snazzy RE would help, but I ended up w/:
    #!/usr/bin/perl -w use strict; my ($readline,$found); my %aok=("Loading Vxd" => 1, # A list of all the different + values "LoadSuccess" => 1, # that should be ignored. Oth +ers are "Loading Device" => 1, # left in for debugging purpo +ses. "LoadSuccess" => 1, "SYSCRITINIT" => 1, "SYSCRITINITSUCCESS" => 1, "DEVICEINIT" => 1, "DEVICEINITSUCCESS" => 1, "Dynamic init device " => 1, "Dynamic init success" => 1, "Dynamic load device " => 1, "Dynamic load success" => 1, "Initing" => 1, "Init Success" => 1, "INITCOMPLETE" => 1, "INITCOMPLETESUCCESS" => 1, "LoadStart" => 1, "Init" => 1, "InitDone" => 1, "Status" => 1, ); my $debug = 0; open BOOTLOG, "<C:\\bootlog.txt" or die ("Error: could not open c:\\bo +otlog.txt\n$!\n"); # Open up the file while (<BOOTLOG>) { my $readline = $_; chomp; my ( $key, $val); s/^\[\w*\]\s*//; # ditch the [A000134] junk for ease of splitting if ( /=/ ) { # lines w/ '=' have just 2 parts ( $key, $val ) = split(/\s+=\s+/); } else { # lines w/o '=' are key words ... value; e.g. value is the last word (my @key_val ) = split(/ /); $val = pop @key_val; $key = join " ", @key_val; } print "$readline" unless ($aok{$key}); # Check against %aok if its i +gnorable; if not, print. #print "$key = $val\n" unless ($aok{$key}); # if don't care about th +e "[mem addr]" part }
    Not as nifty as it could be but faster.

    a

      Thanks... I'm looking into your code now: there's a lot I don't understand in there (like the indexing by key) but I'll have a good look.

      I could probably have just searched for lines containing FAIL (any case) but wasn't sure if that'd fail to report some other errors.

        Nothing special, its just a way to speed up searches when you have well defined search keys. You can do:
        $search_for = 'Failed|Ugly|Broken'; while (<LOG>) { print if /$search_for/; ...
        if you don't have a whole lot of items (or so I look at it, probably benchmarkably wrong) but if you've got a larger number, using a hash is a nice way to speed it up over the iterate through an array approach you used. It needs to be something like this, where the looked for text is consistent, though.

        The only other sneakiness (besides lopping of the initial memory (?) hex in brackets part to make the split-ing easier) was to see that there were 2 kinds of data lines; one w/ an = and variable left-hand side words and one w/o the = and the last word always being the 'result'.

        'course I wrote the mess before recognizing that you were printing unless the data matched a list item.

        a

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://63098]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2014-12-17 21:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (33 votes), past polls