M
MattJ83
Hi,
I've written some code which is almost complete but am having trouble
at the final hurdle.
My code looks for the string FASTSEARCH - if this line is not here - i
want the program to exit.
If there is an error message where the FASTSEARCH string should be -
return this value and carry on with the script. If there is no error OR
FASTSEARCH - the script should terminate.
The script seems to return the correct values when i ask it to print
them - but i am trying to put them into a database - and it isn't
working as the 'print on screen' is.
Any help would be appreciated.
Working code:
#!/usr/central/bin/perl
use strict;
use warnings;
my @filenames = </home/username/logs/*.log>;
foreach my $filename (@filenames)
{
open my $LOG, '<', $filename or die "can't open $filename: $!\n";
print "$filename\n";
my ($fast, $error, $inversions);
while(<$LOG>) {
if (/updates table/) {
/Rows in fast-search index updates table: (.*)/;
print "$1\n";
}
if (/deletions table/) {
/Rows in fast-search index deletions table: (.*)/;
print "$1\n";
}
if (/elapsed/) {
if ($fast or $error) {
/deltas: elapsed=(.*), cpu=(.*), user=(.*), sys=(.*), n=(.*)/;
print "$1\n";
last;
}
}
if (/FASTSEARCH/) {
$fast = $_;
}
if (/conflicting/) {
$error = $_;
print "Conflicting Lock Error Found\n";
}
}
while (<$LOG>) {
if (/inversions/) {
$inversions = $_;
}
}
if (!$fast) { <----------if /FASTSEARCH/ is not
found i want the program to exit.
exit; } elsif ($error) {next;} <----------if /conflicting/ is
found I want the script to keep running
if (!$inversions) {
exit; }
close($LOG);
}
Test data:
_________$LOG__________
string string
Rows in fast-search index updates table: 8
Rows in fast-search index deletions table: 6
string
string
string
deltas: elapsed=(0), cpu=(0), user=(0), sys=(0), n=(0)
string
FASTSEARCH <-------this may not be here - if not
exit....else if error
message is here
(/conflicting/) return error
message and go to next log
(carry on)
deltas: elapsed=(0), cpu=(0), user=(0), sys=(0), n=(0)
inversions
deltas: elapsed=(0), cpu=(0), user=(0), sys=(0), n=(0)
I've written some code which is almost complete but am having trouble
at the final hurdle.
My code looks for the string FASTSEARCH - if this line is not here - i
want the program to exit.
If there is an error message where the FASTSEARCH string should be -
return this value and carry on with the script. If there is no error OR
FASTSEARCH - the script should terminate.
The script seems to return the correct values when i ask it to print
them - but i am trying to put them into a database - and it isn't
working as the 'print on screen' is.
Any help would be appreciated.
Working code:
#!/usr/central/bin/perl
use strict;
use warnings;
my @filenames = </home/username/logs/*.log>;
foreach my $filename (@filenames)
{
open my $LOG, '<', $filename or die "can't open $filename: $!\n";
print "$filename\n";
my ($fast, $error, $inversions);
while(<$LOG>) {
if (/updates table/) {
/Rows in fast-search index updates table: (.*)/;
print "$1\n";
}
if (/deletions table/) {
/Rows in fast-search index deletions table: (.*)/;
print "$1\n";
}
if (/elapsed/) {
if ($fast or $error) {
/deltas: elapsed=(.*), cpu=(.*), user=(.*), sys=(.*), n=(.*)/;
print "$1\n";
last;
}
}
if (/FASTSEARCH/) {
$fast = $_;
}
if (/conflicting/) {
$error = $_;
print "Conflicting Lock Error Found\n";
}
}
while (<$LOG>) {
if (/inversions/) {
$inversions = $_;
}
}
if (!$fast) { <----------if /FASTSEARCH/ is not
found i want the program to exit.
exit; } elsif ($error) {next;} <----------if /conflicting/ is
found I want the script to keep running
if (!$inversions) {
exit; }
close($LOG);
}
Test data:
_________$LOG__________
string string
Rows in fast-search index updates table: 8
Rows in fast-search index deletions table: 6
string
string
string
deltas: elapsed=(0), cpu=(0), user=(0), sys=(0), n=(0)
string
FASTSEARCH <-------this may not be here - if not
exit....else if error
message is here
(/conflicting/) return error
message and go to next log
(carry on)
deltas: elapsed=(0), cpu=(0), user=(0), sys=(0), n=(0)
inversions
deltas: elapsed=(0), cpu=(0), user=(0), sys=(0), n=(0)