morgon has asked for the wisdom of the Perl Monks concerning the following question:
I would like to monitor changes to a file on Debian via inotify.
Here my attempt:
The strage behaviour is now that when I run this script on a file and make a change to the file, nothing happens.use strict; use Linux::Inotify2; $|++; my ($file_to_watch)=@ARGV; my $notify = Linux::Inotify2->new or die $!; my $w = $notify->watch ($file_to_watch, IN_MODIFY, \&on_change) or die + $!; sub on_change { my($e)=@_; print $e->fullname, " changed\n"; } while(1) { print "polling\n"; my $n = $notify->poll; print "handled $n events\n"; }
When I then make another change, the event handler is triggered but from then on no more changes are reported...
So strange as it seems the above code on my system only detects the second change made to a file - not quite what I am after...
What am I doing wrong here?
Many thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: inotify problem
by Perlbotics (Archbishop) on Jun 05, 2012 at 21:33 UTC | |
by morgon (Priest) on Jun 05, 2012 at 22:25 UTC | |
|
Re: inotify problem
by Anonymous Monk on Jun 05, 2012 at 20:52 UTC | |
by morgon (Priest) on Jun 05, 2012 at 21:23 UTC |