fastest way to monitor a dir

P

perl.coder

Hi,

I have a perl script running in production which takes a file name
to be scanned continuously and call a user exit shell program
to take action when a string it is looking for is found in
the file. All I do is to sleep for few seconds and wake
and check the size of the file and if it has changed
since last scanned, scan the new lines added since last
scan.

Now the specs has changed. We recently found that
some server process don't write to the same file,
but create a new file (usually timestamped) when
some error condition happens. So now my script
also has to change accordingly. From just monitoring
a file constantly, it also has to monitor the dir to
see whether a new file has been dropped and then start
monitoring it (also stop the earlier file it was monitoring).

So my question is, what is the fastest way to check whether
a new file has arrived in a directory. The new file name
will always have a fixed prefix, with a changing suffix
every time (usually timestamp).

Thanks in advance.
 
P

Peter Makholm

So my question is, what is the fastest way to check whether
a new file has arrived in a directory. The new file name
will always have a fixed prefix, with a changing suffix
every time (usually timestamp).

The only portable solution is just to reread the entire directory as
often as needed. Some operation systems have more effective ways to
monitor the filesystem.

On Linux you can use either Linux::Inotify or Linux::Inotify2 (I don't
know the difference) on other unixy system Sys::Gamin seems to be a
possibility. This is based on Gnome's File Alteration Monitor Gamin,
which implements a generic monitor but uses more effective solutions
if available (like inotify on linux).

//Makholm
 
J

Jürgen Exner

So my question is, what is the fastest way to check whether
a new file has arrived in a directory. The new file name

That totally and completely depends upon what features your OS offers
for monitoring directories.

jue
 
T

Tim Greer

So my question is, what is the fastest way to check whether
a new file has arrived in a directory. The new file name
will always have a fixed prefix, with a changing suffix
every time (usually timestamp).

What operating system are you using this for? That will probably
determine the best solution over another.
 
P

perl.code

What operating system are you using this for? That will probably
determine the best solution over another.

Solaris
AIX
Linux

thanks all for the replies.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top