fastest way to monitor a dir

Discussion in 'Perl Misc' started by perl.coder@ny.com, Nov 7, 2008.

  1. Guest

    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.
     
    , Nov 7, 2008
    #1
    1. Advertising

  2. writes:

    > 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
     
    Peter Makholm, Nov 7, 2008
    #2
    1. Advertising

  3. wrote:
    >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
     
    Jürgen Exner, Nov 7, 2008
    #3
  4. Tim Greer Guest

    wrote:

    > 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.
    --
    Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
    Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
    and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
    Industry's most experienced staff! -- Web Hosting With Muscle!
     
    Tim Greer, Nov 7, 2008
    #4
  5. Guest

    In article <lv%Qk.203$>, Tim Greer says...
    >
    > wrote:
    >
    >> 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.


    Solaris
    AIX
    Linux

    thanks all for the replies.
     
    , Nov 7, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UnVkeQ==?=

    Sub Dir, Virtual dir, what do I use?

    =?Utf-8?B?UnVkeQ==?=, Jun 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    438
    =?Utf-8?B?UnVkeQ==?=
    Jun 12, 2005
  2. ScottZ
    Replies:
    2
    Views:
    376
    Jorgen Grahn
    Nov 2, 2008
  3. Matthew Denner
    Replies:
    1
    Views:
    196
  4. Kga Agk
    Replies:
    2
    Views:
    156
    Kga Agk
    Jun 29, 2009
  5. Nick Gnedin
    Replies:
    2
    Views:
    168
Loading...

Share This Page