Gary Stainburn wrote:
On Thursday 26 Jun 2003 10:38 pm, Jenda Krynicky wrote:

From: Chris Zimmerman <[EMAIL PROTECTED]>

Is there some way that I can write a bit of code that will watch a
directory and as soon as a file is written to that directory,
something is run against that file?  What would be the best way to
turn this into a daemon?

Depends on the OS. Under windows it'd be Win32::ChangeNotify and Win32::Daemon(::Simple)?


I know a while back (12 months?) a talk was given at our local LUG - http://www.wylug.org.uk - about hooks being placed in the Linux kernel so that user mode processed could register an interest in a file or directory and would receive a SIG if any change occured.


FAM provides something similar and I believe uses hooks in the linux kernel on that system and other means on other *nixes. There even exists a Perl module to hook into it (SGI::FAM) good luck getting it to work though, I have had some problems in the recent past as have other posters.


If someone is looking for a non-blocking way to detect new files or changes to files, etc. and doesn't mind a somewhat steep learning curve I would suggest POE, and possibly its pre-built PoCo::DirWatch component.

The OP should see my posts here for somewhat on the subject:

http://nntp.x.perl.org/group/perl.beginners/44639
http://nntp.x.perl.org/group/perl.beginners/44673

I would also suggest using MD5 or SHA1 hashing or something similar to detect true changes to a file, mtime can be faked, and checking a directory mtime on an interval may not lead to any reliable way to determine if the contents of said directory has changed. Combining the hash caching manner suggested previously with using a checksum hash of the files in the directory should give better results in detecting individual file changes.

http://danconia.org

The idea was so that progs like 'top' could become much more efficient by sleeping instead of polling, but I don't know how far along this is, or whether anyone's written a perl module for it yet.

Gary



Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to