[Perl] Same entries in file, but treat them different.
Hi,
I could use some help with a program that examines a log file.
It should output the duration of the steps in minutes.
My problem is that there is no end of a step given, only the begin of a next step.
Actually the problem is that this line comes 3 times, but marks 3 different events:
"Starting Table table loading"
This is the log file (every table_load entry should be 1 line):
Code:
table_load,1304943291,Mon May 9 12:14:51 GMT 2011,STATUS: Sorting of Table data file started.
table_load,1304943750,Mon May 9 12:22:30 GMT 2011,STATUS: Starting Table table loading.
table_load,1304947100,Mon May 9 13:18:20 GMT 2011,STATUS: Sorting of Table1 data file started.
table_load,1304947546,Mon May 9 13:25:46 GMT 2011,STATUS: Starting Table table loading.
table_load,1304950974,Mon May 9 14:22:54 GMT 2011,STATUS: Sorting of Table2 data file started.
table_load,1304951297,Mon May 9 14:28:17 GMT 2011,STATUS: Starting Table table loading.
table_load,1304954040,Mon May 9 15:14:00 GMT 2011,STATUS: Creating Table indexes.
table_load,1304956993,Mon May 9 16:03:13 GMT 2011,STATUS: Analyzing table Table.
table_load,1304957476,Mon May 9 16:11:16 GMT 2011,STATUS: End of table_load.
This is the program:
Code:
#!/bin/perl -w
use strict;
my @log_lines;
my $log_line;
my $SortTable_Start = 0;
my $SortTable_End = 0;
my $SortTable_Duration = 0;
my $LoadTable_Start = 0;
my $LoadTable_End = 0;
my $LoadTable_Duration = 0;
my $SortTable1_Start = 0;
my $SortTable1_End = 0;
my $SortTable1_Duration = 0;
my $LoadTable1_Start = 0;
my $LoadTable1_End = 0;
my $LoadTable1_Duration = 0;
my $SortTable2_Start = 0;
my $SortTable2_End = 0;
my $SortTable2_Duration = 0;
my $LoadTable2_Start = 0;
my $LoadTable2_End = 0;
my $LoadTable2_Duration = 0;
my $IndexTable_Start = 0;
my $IndexTable_End = 0;
my $IndexTable_Duration = 0;
my $AnalyzeTable_Start = 0;
my $AnalyzeTable_End = 0;
my $AnalyzeTable_Duration = 0;
open (LOGOUT, "</tmp/log.out");
@log_lines = <LOGOUT>;
foreach $log_line (@log_lines) {
if ( $log_line =~ m/Sorting of Table data file started/ ) {
$SortTable_Start = $1 if ( $log_line =~ m/(\d+)/ );
}
if ( $log_line =~ m/Starting Table table loading/ ) {
$LoadTable_Start = $1 if ( $log_line =~ m/(\d+)/ );
$SortTable_End = $LoadTable_Start;
}
if ( $log_line =~ m/Sorting of Table1 data file started/ ) {
$SortTable1_Start = $1 if ( $log_line =~ m/(\d+)/ );
$LoadTable_End = $SortTable1_Start;
}
if ( $log_line =~ m/Starting Table table loading/ ) {
$LoadTable1_Start = $1 if ( $log_line =~ m/(\d+)/ );
$SortTable1_End = $LoadTable1_Start;
}
if ( $log_line =~ m/Sorting of Table2 data file started/ ) {
$SortTable2_Start = $1 if ( $log_line =~ m/(\d+)/ );
$LoadTable1_End = $SortTable2_Start;
}
if ( $log_line =~ m/Starting Table table loading/ ) {
$LoadTable2_Start = $1 if ( $log_line =~ m/(\d+)/ );
$SortTable2_End = $LoadTable2_Start;
}
if ( $log_line =~ m/Creating Table indexes/ ) {
$IndexTable_Start = $1 if ( $log_line =~ m/(\d+)/ );
$LoadTable2_End = $IndexTable_Start;
}
if ( $log_line =~ m/Analyzing table Table/ ) {
$AnalyzeTable_Start = $1 if ( $log_line =~ m/(\d+)/ );
$IndexTable_End = $AnalyzeTable_Start;
}
if ( $log_line =~ m/End of table_load/ ) {
$AnalyzeTable_End = $1 if ( $log_line =~ m/(\d+)/ );
}
}
close (LOGOUT);
$SortTable_Duration = $SortTable_End - $SortTable_Start;
$SortTable_Duration = sprintf ("%.0f", ($SortTable_Duration / 60));
$LoadTable_Duration = $LoadTable_End - $LoadTable_Start;
$LoadTable_Duration = sprintf ("%.0f", ($LoadTable_Duration / 60));
$SortTable1_Duration = $SortTable1_End - $SortTable1_Start;
$SortTable1_Duration = sprintf ("%.0f", ($SortTable1_Duration / 60));
$LoadTable1_Duration = $LoadTable1_End - $LoadTable1_Start;
$LoadTable1_Duration = sprintf ("%.0f", ($LoadTable1_Duration / 60));
$SortTable2_Duration = $SortTable2_End - $SortTable2_Start;
$SortTable2_Duration = sprintf ("%.0f", ($SortTable2_Duration / 60));
$LoadTable2_Duration = $LoadTable2_End - $LoadTable2_Start;
$LoadTable2_Duration = sprintf ("%.0f", ($LoadTable2_Duration / 60));
$IndexTable_Duration = $IndexTable_End - $IndexTable_Start;
$IndexTable_Duration = sprintf ("%.0f", ($IndexTable_Duration / 60));
$AnalyzeTable_Duration = $AnalyzeTable_End - $AnalyzeTable_Start;
$AnalyzeTable_Duration = sprintf ("%.0f", ($AnalyzeTable_Duration / 60));
printf "SortTable_Duration : $SortTable_Duration minutes\n";
printf "LoadTable_Duration : $LoadTable_Duration minutes\n";
printf "SortTable1_Duration : $SortTable1_Duration minutes\n";
printf "LoadTable1_Duration : $LoadTable1_Duration minutes\n";
printf "SortTable2_Duration : $SortTable2_Duration minutes\n";
printf "LoadTable2_Duration : $LoadTable2_Duration minutes\n";
printf "IndexTable_Duration : $IndexTable_Duration minutes\n";
printf "AnalyzeTable_Duration : $AnalyzeTable_Duration minutes\n";
Hi All ,
I have an output value with two columns like this...
Days User
10 A
500 B
1 C
How i can compare the first column value and passing the user name as parameter?
For example :
while read -r days
If (days<=30) ;
then
value=days/30 x100
... (3 Replies)
Hi -
Trying to take a list of ldap suffixes in a file, run an ldapsearch command on them, then run a grep command to see if it's a match, if not, then flag that and send an email alert.
The list file (ldaplist) would look like -
***********
o=company a
o=company b
***********
**... (7 Replies)
I need a script that reads the out put of a command (softwareupdate --list) and will tally up the number of asterisks in the output and tell me how many there were. How do I go about getting my script to treat asterisks as a regular character and not a wildcard or some other operator? (8 Replies)
Hi everyone!
first of all thank you all for the forum.
My question is, is there a bash or java program, which addresses the existing text in the html that is visible in the web page for editing by another string, eg
name1: flakjsdlñfjas
Name of father: fdfjaksdfjskdfsd
Well it... (1 Reply)
I've been finding myself using a log file colorizer written in perl to reformat and colorize the output from many different programs. Mainly, however, I use it to make the output from "tail -f" commands more readable.
The base perl script I use is based on "colorlogs.pl" available from the... (1 Reply)
Hi.
Before I've post this question, I have spent hours looking for the solutions but to no avail. Because I think it is possible but I just don't know what is the right keyword to search for.
Ok, basically what I want to achieve is really simple.
It's just that I don't want to write... (20 Replies)