Claudia Agrelo wrote:
> I am new with Perl, can someone help me?
> I have the following LOG file, i want to extract the date (Thu Nov 30
> 14:12:07 CET 2006)
> and the amount of httpd instances running (30). I am making the script
> and i was able to
> extract the number of instances but i really dont know how can i parse
> perl to extract the
> date.
> I would really appreciate your help
> Thanks
> Ana
>
> ###########################LOG#########################
>
> green Thu Nov 30 14:12:07 CET 2006 All processes are OK
>
> &green /usr/local/apache2/bin/httpd -k start -DSSL >=1 - 30 instances
> running
>
> Status unchanged in 21.59 days
> Status message received from 197.123.18.79
>
> ################## SCRIPT ####################################
I'm assuming the lines you want are always the first two (change if not true):
my $log = 'somelogfile.log';
open LOG, $log;
my $lineno = 0;
while (defined ($line = <LOG>)) {
chomp $line;
++$lineno;
print "$lineno: $line\n" if $debug;
if ($lineno == 1) {
# green Thu Nov 30 14:12:07 CET 2006 All processes are OK
my @f = split ' ', $line; # split words
printf "%s: date='%s'\n", $log, join ' ', @f[1..6];
} elsif ($lineno == 2) {
if ($line =~ /^\&(green|yellow|red).*\s+(\d+)\s+instances/i) {
print "$log: Instances $2\n";
} else {
print "$log: Bad instance line $line\n";
}
} else {
last; # after two lines quit
}
}
close LOG;
__END__
> open(LOG,"$log");
> while ( defined ($line = <LOG>) ) {
> chomp $line;
> #print "$line\n";
> # ensure colour is valid - ie don't graph purple results
> if($line =~ /green|yellow|red/) {
>
>
> # if($line =~ /(\d+)\s+instances/o){
> $httpd=$1;
> print "las instancias de $host son $httpd\n";
> }
> $colour_check="ok";
> }
> if ($colour_check ne "ok") {
> print "$0: WARN $host is not showing red, yellow, or green. $log
> skipped.\n" if ($ENV{'WARN'});
> }
>
> }
> if ($colour_check=="ok"){
> $text = "httpd instances: $httpd \n,";
>
> ####################################################################
_______________________________________________
Perl-Unix-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs