Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

logging ftp log into mysql db...

by perlknight (Pilgrim)
on Apr 01, 2006 at 13:39 UTC ( [id://540635]=perlquestion: print w/replies, xml ) Need Help??

perlknight has asked for the wisdom of the Perl Monks concerning the following question:

I want to log ftp log into mysql db, one gotcha which I need help in in how to keep track of which line I was at so that the next iteration will skip. I am thinking of something like this:
if new file { read all lines and insert into db. current_line is the last line } else if not new file { go to current_line read all new lines and insert into db }
Any thoughts on this? Thanks.

Replies are listed 'Best First'.
Re: logging ftp log into mysql db...
by McDarren (Abbot) on Apr 01, 2006 at 14:39 UTC
      Do you know if File::Tail takes into account when the log files get rotated? Thanks.
        Well, from the docs:
        If the file does not get altered for a while, File::Tail gets suspicio +us and starts checking if the file was truncated, or moved and recreated. + If anything like that had happened, File::Tail will quietly reopen the + file, and continue reading. The only way to affect what happens on reopen is by setting the reset_ +tail parameter (see below). The effect of this is that the scripts need not be aware when the logf +iles were rotated, they will just quietly work on.
        So I would say the answer to that question is yes :)
Re: logging ftp log into mysql db...
by roboticus (Chancellor) on Apr 01, 2006 at 17:12 UTC
    perlknight--

    The other solutions are good, but your pseudocode suggests that you're looking for the functions seek() and tell(). Augmenting your pseudocode a little:

    if new file { # read all lines and insert into db. # Save current position for next time... $current_line = tell(FH); } else if not new file { # Go to current line seek(FH,0,$current_line); # read all new lines and insert into db # Save position for next iteration... $current_line = tell(FH); }
    --roboticus
Re: logging ftp log into mysql db...
by srdst13 (Pilgrim) on Apr 01, 2006 at 16:20 UTC
    For extreme overkill, you could look at monitoring the file(s) using POE.

    Sean

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://540635]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-05-28 14:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found