Operating System - HP-UX
1826312 Members
4456 Online
109692 Solutions
New Discussion

Re: Writing into log file - Scripting

 
Archana1
Frequent Advisor

Writing into log file - Scripting

Hello Experts,

Please help me simple scripting -

which captures ERROR,WARN,FATAL entries between 6 AM - 6PM (Monday - Friday) and should put in seperate log file.

Here is my log file :-
2010-03-30T16:12:42,728 ERROR [00000008] :sassrv - ERROR: Failed to retrieve log
in credential from the authentication domain.
2010-03-30T16:12:42,728 ERROR [00000008] :sassrv - ERROR: Failed to retrieve log
in credential from the authentication domain.

2010-04-15T01:21:54,847 [00000004] sas - Option (0x5) dnsMatch
2010-04-15T01:21:54,890 [00000004] sas - value (0x0) sasseam.uk.capi
talone.com
2010-04-15T01:21:54,899 [00000004] sas - Option (0xe) sasspawnercn
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: Writing into log file - Scripting

Hi:

You could use:

# cat ./filter
#!/usr/bin/perl
use strict;
use warnings;
while (<>) {
next unless m{(?:ERROR|WARN|FATAL)};
( my $time ) = (m{^\d{4}.{6}T(\d\d)});
print if ( $time <= 18 && $time >= 6 );
}
1;

...run as:

# ./filter logfilename > results

I presume that your log is a daily one, recreated every day. In that case, simply 'cron' this script to run sometime after 1800 hours.

Regards!

...JRF...
Archana1
Frequent Advisor

Re: Writing into log file - Scripting

Hi, Thanks for response.

Below is the error I found with script. Please help in trouble shoot.

$ ./filter.sh ObjectSpawner.log > results.log
./filter.sh[5]: use: not found.
./filter.sh[6]: use: not found.
./filter.sh[7]: Syntax error at line 7 : `)' is not expected.

$ perl -v

This is perl, v5.8.8 built for IA64.ARCHREV_0-thread-multi

Copyright 1987-2006, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
Steven Schweda
Honored Contributor

Re: Writing into log file - Scripting

> $ ./filter.sh ObjectSpawner.log > results.log
> ./filter.sh[5]: use: not found.
> [...]

Apparently, your "filter.sh" script differs
from the suggested "filter" script, but, with
my weak psychic powers, I can see only one of
the two, and it's not yours.

cat filter.sh
James R. Ferguson
Acclaimed Contributor

Re: Writing into log file - Scripting

Hi (again):

> Below is the error I found with script.

You changed the interpreter (she-bang) or dropped it entirely. The script's first line should read something like:

#!/usr/bin/perl

...or whatever is the absolute path to your perl executable.

You could also dynamically find perl in your PATH by using:

#!/usr/bin/env perl

Note the whitespace before the word 'perl'.

Regards!

...JRF...