On Wednesday, July 10, 2002, at 09:12 , John W. Krahn wrote:
[..]
>
> Something like that.  :-)  But what if the log file has been rotated and
> the last line is no longer in the file?
>
> my $last_line = get_last_line_from_cache();
>
> open LOG, .... or die "$!";
>
> while ( <LOG> ) {
>     rollback_db_data() if $_ eq $last_line;
>
>     process_db_data();
>
>     $last_line = $_ if eof( LOG );
>     }
>
> commit_db_data();
>
> push_into_cache( $last_line );

that is why I was thinking of avoiding the 'walk the file'
approach by caching the stat data - especially if the file
is like say syslog where there is a known 'step back' strategy
that IF  /var/adm/messages has been rolled check /var/adm/mess*.[0-N]
till you find your correct one...

        cf perldoc -f stat

hence

        my $cache_hash_ref = get_hash_from_cache();

        open(LOG, ....)
        my @stat_dope = lstat(LOG);

        if ( $stat_dope[7] > $cache_hash_ref->{stat_size} ) {
                #
                # the file has grown, we need to lseek forward to
                # $cache_hash_ref->{stat_size}
                lseek_der_log();
                
        } else {
                # fremonge they rolled the log so let's solve that
                # one and then come back through here...
                grovel_prior_log($cache_hash_ref);
                $new_log++;     # boolean initialized to 0
                                        # set here since after we finish processing
                                        # will need to check if we should 
whine_at_apes();
        }

        #
        # in theory at this point we are looking at the correct
        # line of dope in the Log to grovel...
        #

yes, there are those who like to check ino.... but...

ciao
drieux

---


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

Reply via email to