John,

Thanks for the info.  I am a bit confused in the first part of the script.

my %servers;  (This is defining a hash?)
open (I understand)
{
chomp (my @temp = <SVRS>); (Removing the newline from each entry)
@server{ @temp } =(); (What's this do?);
}

Thanks,

Craig

>>> "John W. Krahn" <[EMAIL PROTECTED]> 11/26/01 10:24AM >>>
Craig Sharp wrote:
> 
> I am lost.  I have the following script that opens the log file WUGEvent.log and 
>looks for the
> statment "UP", replaces spaces and writes out the new log file.  It works great!
> 
> Here is the problem.  I need to read in another file (wuglist.txt) containing a list 
>of server
> names and then compare each name to the line currently being processed.  Then if it 
>matches,
> write the line out to a new file following the conversion.
> 
> I tried to read the server name from the file into a variable and add a && to the 
>reg expression
> looking for UP but it did not work:
> 
> if (/\bUP\b/ && $server_name)
> 
> I am lost in how to setup the loop and compare.
> 
> Here is the script and sample log files:
> 
> #!/usr/bin/perl
> 
>#--------------------------------------------------------------------------------------
> # log_convert.pl script
> 
>#--------------------------------------------------------------------------------------
> 
> open (inlogfile, "WUGEvent.log") || die "$!\n";
> open (outlogfile, ">newlog.log") || die "$!\n";
> @lines = <inlogfile>;
> select outlogfile;
> foreach (@lines) {
>   chomp;
>   if (/\bUP\b/) {
>     s/\t+/|/g;
>     s/missed //g;
>     print "$_\n";
>     }
>   }
> close inlogfile;
> close outlogfile;
> 
>  ------------------------------------------------------------------------------------
> Sample WUGEvent.log
> 
> 20011022        143514  C:\Program Files\WhatsUp\b31.wup        UP      roush_31
>        10.31.1.1       missed 4
> 20011022        143515  C:\Program Files\WhatsUp\b31.wup        Alert   successful
> process N:roush_31 F:768 A:SMTPMail/Beryl (e-mail)
> 
> [ snip ]


Here is one way to do it:

#!/usr/bin/perl -w
use strict;
#--------------------------------------------------------------------------------------
# log_convert.pl script
#--------------------------------------------------------------------------------------

my %server;
open SVRS, 'wuglist.txt' or die "Cannot open 'wuglist.txt': $!";
{
chomp( my @temp = <SVRS> );
@server{ @temp } = ();
}
close SVRS;


open INLOGFILE, 'WUGEvent.log' or die "Cannot open 'WUGEvent.log': $!";
open OUTLOGFILE, '>newlog.log' or die "Cannot open 'newlog.log': $!";

while ( <INLOGFILE> ) {
    my @fields = split;
    if ( $fields[4] eq 'UP' and exists $server{ $fields[5] } ) {
        print OUTLOGFILE "@fields[0..6,8]";
        }
    }

close INLOGFILE;
close OUTLOGFILE;

__END__



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED] 
For additional commands, e-mail: [EMAIL PROTECTED] 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to