Here my code, I am looking for any way to optimize it so it will read
these log files slightly faster if possible...

This is taking anywhere from 1min to 4mins depending on log file size...

-- Begin of Code --

my $date = &get_date();

my $rahome = "/rahome/bridge_logs/logs/";
my @bridges = ("80","81","82","83","84","85","86","87");
my @checks = qw(alarm, ASSERTION, Bus, SYSERR, emt, bounce, arbitration,
Address, died, EMT, FAILURE, Illegal,
Retransmitting);
print "Started at " . localtime() . "\n";
foreach (@bridges) {
        &read_dir($_,$date);
}
print "Finished at " . localtime() . "\n";
# end of main

# Do not edit anything below this line unless you know what you are
doing.
#
--------------------------------------------------------------------------

# subfunctions

# name: get_date
# description: this sub grabs the latest date and returns it in YYYYMMDD
format.
sub get_date {
        my ($day,$month,$year) = (localtime)[3..5];
        $year += 1900; # needed since mytime returns year as 1900
        $month += 1; # needed since month is an array and offset by one.
        if ($month < 10) {
                $month = 0 . $month;
        } # end of if
        my $return = $year . $month . $day; # lets put this into a nice format.
        return $return;
} # end of sub

# name: read_dir
# description: This will go to the rahome dir and check for log dirs...
sub read_dir {
        my ($brg,$date) = @_;
        my $bdir = $rahome . "bridge$brg";
        my @logs = ();
        opendir(DIR, $bdir) or warn "Could not open $bdir: $!\n";
        while (defined(my $file=readdir DIR)) {
                next if -f "$bdir/$file"; #no files here just dirs.
                next if $file =~ /^\.\.?$/; # ignore . and ..
                if (-d "$bdir/$file") {
                        my $blog = $bdir . "/" . $file . "/" . "$date.log";
                        push(@logs,$blog);
                }
        }
        closedir DIR;
  &parse_log(@logs);
}
# name: parse_log
# description: This sub will tear apart a log file and check for the
search string given to it from read_config
sub parse_log {
        my (@blogs) = @_;
        my @log = ();
        foreach $log (@blogs) {
                print "Reading $log\n";
                open(LOG,"$log") or warn "Could not open $log: $!\n";
                while(<LOG>) {
                        chomp;
                        $line = $_;
                        if ($line !~ /^\d/) {
                                next;
                        }        # end of if
                        my @split = split(/\|/,$line); # making it more managable.
                        # Now since voyant sucks and does not use a set column system 
we have
to go through every split field
                        # for the search string... patrol does this too but not as 
clean as
we will ;)
                        #print "$rdate $rtime\n";
                        foreach $string (@checks) {
                                #print "checking for $string\n";
                                if ($split[6] =~ /$string/) {
                                        print "Ok found $string in $split[6]\n";
                                } # end of if
                          if ($split[7] =~ /$string/) {
                                                print "Ok found $string in 
$split[7]\n";
                          } #end of if
                        } # end of foreach
                } #end of while
                close LOG;
        } # end of foreach      
}
        
-- End of Code --


-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Richie Crews

Unix Administrator / Internet Integrator

Email: [EMAIL PROTECTED]

Cell: (706) 773 - 3436
Desk: (706) 634 - 3681
Fax: (706) 634 - 3831

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Reply via email to