logging ftp log into mysql db...
perlknight
created: 2006-04-01 08:39:03
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.
Re: logging ftp log into mysql db...
created: 2006-04-01 09:39:46
Why don't you have a look at File::Tail?
Re^2: logging ftp log into mysql db...
created: 2006-04-02 09:56:53
Do you know if File::Tail takes into account when the log files get rotated? Thanks.
Re^3: logging ftp log into mysql db...
created: 2006-04-02 10:20:56
Well, from the docs:
If the file does not get altered for a while, File::Tail gets suspicious 
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 logfiles 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...
created: 2006-04-01 11:20:17
For extreme overkill, you could look at monitoring the file(s) using POE.

Sean
Re: logging ftp log into mysql db...
created: 2006-04-01 12:12:45
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

perlmonks.org content © perlmonks.org and McDarren, perlknight, roboticus, srdst13

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03