Professional Web Applications Themes

File Monitoring - PERL Beginners

Hi there, Can anyone recommend a good way to have a perl script that constantly monitors for the creation of new files on UNIX and launches another process? Thanks! Cheers, Ben...

  1. #1

    Default File Monitoring

    Hi there,

    Can anyone recommend a good way to have a perl script that constantly
    monitors for the creation of new files on UNIX and launches another
    process?

    Thanks!

    Cheers,
    Ben

    Perldiscuss Guest

  2. #2

    Default Re: File Monitoring



    PerlDiscuss - Perl Newsgroups and mailing lists wrote:
     

    Hello,
     

    Not sure if someone else recommended this but:

    [untested code - for example only]
    #!/usr/bin/perl

    use strict;
    use warnings;

    while(1) {
    opendir DIRH, '/foo/bar' or die $!;
    my curlst = <DIRH>;
    closedir(DIRH);
    if(grep /watch for me/, curlst) {
    # launch other process here...
    }
    sleep(15);
    }

    Then start it running like so:
    ../thisscript.pl &
     

    np, HTH

    Lee.M - JupiterHost.Net
     
    Jupiterhost.Net Guest

  3. #3

    Default Re: File Monitoring

    Hi, I've done this app. What I do is put into a file the output of
    ls -lR /directory_to_watch.
    Then use diff to compare the results. This gives the advantage that,
    if a line starts with +, then a new file has been added. If it's -, a
    file has been deleted :)

    $ ls -lR > listing1.txt
    $ ls -lR > listing2.txt

    $ diff listing1.txt listing2.txt > diff.txt


    Of course, this works on a Un*x environment.

    Dani Guest

  4. #4

    Default Re: File Monitoring

    > Hi there, 

    Lee's method would be the sufficient underkill way. I have an
    application that does this type of thing that was written using POE,
    which made it trivial, but may make it overkill. For us we needed the
    extensibility and scalability that POE offered so it wasn't overkill.

    There is a directory watching component in POE or you could grow your
    own, sorry I can't provide the one I have (licensing issues).
    POE::Wheel::Run is ideal for managing external processes called from
    within the app.

    http://poe.perl.org

    Has more, be warned there is a learning curve here...

    http://danconia.org

    Wiggins Guest

  5. #5

    Default RE: File Monitoring

    > > -----Original Message----- 
    >
    > [snip]

    >
    > Where to find doc on that (link) ?
    >[/ref]

    http://search.cpan.org/~cholet/POE-Component-DirWatch-0.01/DirWatch.pm
     
    >
    > Why did you re-invented the wheel ;)
    > Or Am I missing some basic infos ?
    >[/ref]

    Good question. Several reasons, mostly dealing with our application
    overall.

    1. The component mentioned is a very good example of using POE's inline
    sessions to do a polling type of activity but isn't terribly robust (I
    don't believe it was designed nor needs to be as a core component).

    2. The callback interface didn't quite suit our needs as we were going
    for more of an overall OOP structure and wanted continuity across the
    app components.

    3. I found it difficult to manage the directory watchers, for a couple
    it would be sufficient but we were talking about upwards of 40 to start,
    with more coming in the future. One of the key goals of our app was to
    have the ability to pause/resume as well as start/stop a particular
    watcher at any given time, the session based watcher made this more
    difficult (in my mind) than an object based one.

    4. As a production app in a financial organization we needed a lot of
    logging, and scalability, but could sacrifice development time and
    maintenance. We also wanted the logging to be seemless across the app,
    so we built the logging directly into the watcher we made.

    In the end because of the simplicity of the base module I don't know
    that we reinvented the wheel, more like just put a nice steel belted
    tire around it :-). The underlying session that forms the core of the
    component is still intact, the same events are used, but the data
    structure itself is more accessible and the HEAP usage was dropped in
    favor of a standard OOP hash. These things made it simpler to control
    the session since it is just a basic Perl object and will allow us to
    change the implementation in the future if need be since it is
    completely encapsulated (aka no fussing with POE events outside the
    object's internal implementation).

    I am still attempting to get the organization to allow me to release it,
    that or I may build "my own" from scratch and incorporate it into
    another app that I can release :-). But there is no timeline for all of
    that...

    http://danconia.org
    Wiggins Guest

  6. Moderated Post

    Default Re: File Monitoring

    Removed by Administrator
    Dani Guest
    Moderated Post

  7. #7

    Default Re: File Monitoring

    On Mon, May 10, 2004 at 08:35:53AM -0600, Wiggins d Anconia wrote: 
    There is also the FAM daemon, which taps into the kernel to do it. I'm
    sure that there is a perl module to talk to that.

    --
    Robin <net.nz> JabberID: <org>

    Hostes alienigeni me abduxerunt. Qui annus est?

    PGP Key 0x776DB663 Fingerprint=DD10 5C62 1E29 A385 9866 0853 CD38 E07A 776D B663

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFAoDKfzTjgendttmMRArbVAJ4yIoimAnaQnwwQ5hJ3Wa qxM0ZL8wCeNnz+
    EyLFeUCJip5j2Z9BwL1KHj4=
    =s+p2
    -----END PGP SIGNATURE-----

    Robin Guest

  8. #8

    Default Re: File Monitoring


    > There is also the FAM daemon, which taps into the kernel to do it. I'm
    > sure that there is a perl module to talk to that.[/ref]

    Yep, SGI::FAM, good luck getting it to work, that is not to say that you
    can't, in fact I did at one point in one version of Linux with one
    version of fam, but recently I haven't had much luck, especially on
    anything but Linux (aka solaris 8/9). I know fam is still used, and
    should actually be getting more popular since I believe parts of Gnome
    use it now, but the Perl module does not appear to be maintained. Check
    the archives for my other posts about this particular subject. Maybe
    this summer I will have a stab at hacking it up again, alas, I am not
    much of a C, let alone kernel, hacker.

    Back to the app I mentioned, initially when developing it I had planned
    on using fam, after having the problems we had and growing our own, I
    would say I am not likely to re-implement even if it were available and
    of production quality, the robustness we have seen with our app in POE
    just doesn't make switching worth it. fam would be superior if you need
    true file watching, as opposed to directory watching (subtle difference
    but important).

    http://danconia.org
    Wiggins Guest

Similar Threads

  1. Monitoring FMS
    By RonReed67 in forum Macromedia Flash Flashcom
    Replies: 1
    Last Post: February 15th, 06:11 PM
  2. NTFS Permissions & "Failed to Start Monitoring File Changes"
    By Alex Maghen in forum ASP.NET Security
    Replies: 0
    Last Post: February 3rd, 02:21 AM
  3. Failed to start monitoring file changes.
    By Mark in forum ASP.NET Web Services
    Replies: 15
    Last Post: May 5th, 03:14 PM
  4. select / monitoring file change
    By ssk in forum UNIX Programming
    Replies: 4
    Last Post: August 20th, 03:52 PM
  5. Access denied to Failed to start monitoring file changes.
    By Carl Prothman [MVP] in forum ASP.NET General
    Replies: 0
    Last Post: August 6th, 05:29 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139