"Sagar, Sanjeev" wrote:

> Big Thanks !
>
> My log file looks like below

Would be better with multiple sections, and only a few representative line
per...

> 2004-03-26 @ 00:00:01 [EMAIL PROTECTED] -- 10881 10864 hyb01
> :INFORMATIONAL
>

...

> Script/function sql_instance_ping_final started at Fri Mar 26 00:00:04 CST
> 2004 -- seconds -- 4:INFORMATIONAL
>
> Any idea on reseting %datastore will be highly appreciable.

Yes it will take an appreicable effort to come up with any ideas.  What do you
want this script to do for you?  Do you want to have all the log information in
memory so that you can compare between checks?  In that case you will probably
want a ahs of hash references.  The keys of the outer hash would probably be the
times of the checks The value for each key would be a reference to an anonymous
hash containing all of the status keys and their values for a given checktime.

You can make use of the file structure in deciding when to add one set of status
vlues to your ahs and start the next.

You know that:

Each check-time record starts with a series of lines, each of which starts with
a specifically formatted date and time string.
The end of the report is marked by a constant string;
Variable_name   Value
This constant string is followed by the name-value pairs you seek to organize.

So clearly, the first date formatted string you encounter on each timecheck
should signal you to store the previous anonymous hash, and to get the date
information that will be the key of the next.  Depending on whether you are
making use of the information contained in the header lines, you will process
them or not while watching for the constant string /^Variable_name   Value$/
which will signal your program to start collecting the key-value pairs for the
current time-check.

Joseph

Somthing like this:

Greetings! E:\d_drive\perlStuff>perl -w
my %time_checks;
my $line = <DATA>;
while ($line) {
   my $current_time;
   if ($line =~ /^(\d{4}-\d{2}-\d{2} \@ \d{2}:\d{2}:\d{2})/) {
      $current_time = $1;
   }
   $line = <DATA> until $line =~ /^Variable_name   Value$/;
   my $current_values = {};
   $line = <DATA>;
   until ($line =~ /^(\d{4}-\d{2}-\d{2} \@ \d{2}:\d{2}:\d{2})/) {
      chomp $line;
      last unless $line;
      my ($key, $value) = split /\s+/, $line;
      $current_values->{$key} = $value;
      $line = <DATA>;
   }
   $time_checks{$current_time} = $current_values;
   chomp $line;
}

foreach $time_check (sort keys %time_checks) {
   print "\n\n$time_check:\n";
   my $check_values = $time_checks{$time_check};
   print "   $_: $check_values->{$_}\n" foreach (keys %$check_values);
}

__DATA__
2004-03-26 @ 00:00:01 [EMAIL PROTECTED] -- 10881 10864 hyb01
:INFORMATIONAL
2004-03-26 @ 00:00:01 [EMAIL PROTECTED] -- 10881 10864 hyb01 Function
(up) returned (0) return code. -- seconds -- 1:INFORMATIONAL
Variable_name   Value
Aborted_clients 5592
Aborted_connects        4
Bytes_received  500
Bytes_sent      5000
Com_admin_commands      0
Com_alter_table 27
Com_analyze     0
Com_backup_table        0
2004-03-26 @ 00:15:01 [EMAIL PROTECTED] -- 10881 10864 hyb01
:INFORMATIONAL
2004-03-26 @ 00:15:01 [EMAIL PROTECTED] -- 10881 10864 hyb01 Function
(up) returned (0) return code. -- seconds -- 1:INFORMATIONAL
Variable_name   Value
Aborted_clients 5592
Aborted_connects        4
Bytes_received  2678
Bytes_sent      6935
Com_admin_commands      0
Com_alter_table 29
Com_analyze     0
Com_backup_table        0
2004-03-26 @ 00:30:01 [EMAIL PROTECTED] -- 10881 10864 hyb01
:INFORMATIONAL
2004-03-26 @ 00:30:01 [EMAIL PROTECTED] -- 10881 10864 hyb01 Function
(up) returned (0) return code. -- seconds -- 1:INFORMATIONAL
Variable_name   Value
Aborted_clients 5592
Aborted_connects        4
Bytes_received  6023
Bytes_sent      10001
Com_admin_commands      0
Com_alter_table 15
Com_analyze     0
Com_backup_table        0



2004-03-26 @ 00:00:01:
   Bytes_received: 500
   Com_analyze: 0
   Bytes_sent: 5000
   Com_alter_table: 27
   Com_backup_table: 0
   Com_admin_commands: 0
   Aborted_clients: 5592
   Aborted_connects: 4


2004-03-26 @ 00:15:01:
   Bytes_received: 2678
   Com_analyze: 0
   Bytes_sent: 6935
   Com_alter_table: 29
   Com_backup_table: 0
   Com_admin_commands: 0
   Aborted_clients: 5592
   Aborted_connects: 4


2004-03-26 @ 00:30:01:
   Bytes_received: 6023
   Com_analyze: 0
   Bytes_sent: 10001
   Com_alter_table: 15
   Com_backup_table: 0
   Com_admin_commands: 0
   Aborted_clients: 5592
   Aborted_connects: 4




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to