P
Panagiotis Atmatzidis
A salut to the list,
I need read info from a file, extract the info that I want which is the =
date and IP and dump them into a database (mysql).
However, this file gets constantly updated, sits on /var/log/.
Until now I have used just the file.open and file.read methods. However, =
I feel that both ways are not suitable for what I want to do, because I =
will need to make a selection between old and new entries every time my =
script reads the file to extract info.
What is the *standard* (or best) way to manage this situation?
Here is the class which reads the file:
class ReadIPs
def self.ip(log)=20
file =3D File.open(log)
file.each_line do |line|=20
if line.include?("Ban")
a =3D line.split(" ")
date =3D a[0]
ip =3D a[6]
puts "date: #{date} IP: #{ip}"
end
end
file.close
end
end
I use File.open now but I should use something like File.append or =
similar? Note that I will never write to this file, it's just the file =
that contains the info. Every time a new line appears that contains the =
word "Ban" I want to trigger this...
Best regards
Panagiotis (atmosx) Atmatzidis
email: (e-mail address removed)
URL: http://www.convalesco.org
GnuPG ID: 0xFC4E8BB4=20
gpg --keyserver x-hkp://pgp.mit.edu --recv-keys 0xFC4E8BB4
I need read info from a file, extract the info that I want which is the =
date and IP and dump them into a database (mysql).
However, this file gets constantly updated, sits on /var/log/.
Until now I have used just the file.open and file.read methods. However, =
I feel that both ways are not suitable for what I want to do, because I =
will need to make a selection between old and new entries every time my =
script reads the file to extract info.
What is the *standard* (or best) way to manage this situation?
Here is the class which reads the file:
class ReadIPs
def self.ip(log)=20
file =3D File.open(log)
file.each_line do |line|=20
if line.include?("Ban")
a =3D line.split(" ")
date =3D a[0]
ip =3D a[6]
puts "date: #{date} IP: #{ip}"
end
end
file.close
end
end
I use File.open now but I should use something like File.append or =
similar? Note that I will never write to this file, it's just the file =
that contains the info. Every time a new line appears that contains the =
word "Ban" I want to trigger this...
Best regards
Panagiotis (atmosx) Atmatzidis
email: (e-mail address removed)
URL: http://www.convalesco.org
GnuPG ID: 0xFC4E8BB4=20
gpg --keyserver x-hkp://pgp.mit.edu --recv-keys 0xFC4E8BB4