leocharre has asked for the wisdom of the Perl Monks concerning the following question:

This is not exactly perl- just deals with running some on a funky condition..

I want something to detect if there is a change in a directory, and run a script. That is, if a file appears in a certain directory.. i want to automatically wake some script up.

could i have something like that work on a mounted directory?

Hm.. feeling airy in the head.

UPDATE: I'm sorry i'm such a retard! im running linux, ext3 - mounts are NTFS, ext2, etx3..

Replies are listed 'Best First'.
Re: detect directory change
by Corion (Patriarch) on Feb 27, 2006 at 19:11 UTC

    You don't tell us which operating system(s) you are using. If you're using a recent operating system like Windows NT, 2000 or XP, then there is Win32::ChangeNotify, which will allow you to conveniently monitor a directory or a whole tree. For other operating systems, like IRIX or (I believe) Linux, there is SGI::FAM, which also gives you notifications on file system changes.

    I guess that NFS doesn't give you any notifications, so if you mount your drives via NFS, I guess you're out of luck.

    So, if none of the options apply to your situation, you'll have to come forth with more details.

Re: detect directory change
by derby (Abbot) on Feb 27, 2006 at 19:12 UTC
Re: detect directory change
by ambrus (Abbot) on Feb 27, 2006 at 20:45 UTC

    On linux, you can use the F_NOTIFY fcntl. See the fcntl(2) manpage.

Re: detect directory change
by Ace128 (Hermit) on Feb 27, 2006 at 19:41 UTC
    You have Inotify...
Re: detect directory change
by zentara (Cardinal) on Feb 27, 2006 at 20:43 UTC
    Check this out, and there are some similar things in c on freshmeat.net.
    #!/usr/bin/perl use POE::Component::DirWatch; # Take a look at the module POE::Component::DirWatch # on CPAN, I think this might be what you are looking # for. It watches a directory for files, and once a # filename matching the filter is found, it will kick # off a sub-process and invokes the given user callback. POE::Component::DirWatch->spawn( Alias => 'dirwatch', Directory => '/some_dir', Filter => sub { $_[0] =~ /\.gz$/ && -f $_[1] }, Callback => \&some_sub, PollInterval => 1, );

    I'm not really a human, but I play one on earth. flash japh