As qmechanik very wisely suggested, the inotify-utils
are an excellent
starting point for this situation. Allow programs to be enabled when the file/ directory changes.
Below are two program skeletons (one in perl and one in bash) where you can easily graft your experiences...
#!/usr/bin/perl
use Linux::Inotify2;
my $inotify = new Linux::Inotify2 or die "unable to inotify: $!";
$inotify->watch ("Dir", IN_MODIFY, ## or in_{acess,create,open, etc...}
sub { my $e = shift;
my $name = $e->fullname;
## whatever
print "$name was modified\n" if $e->IN_MODIFY;
});
1 while $inotify->poll;
Or using only cite shell{https://unix.stackexchange.com/a/193392/96276}:
while inotifywait -qqe modify "$DIRECTORY"
do
process_the_directory "$DIRECTORY"
done
See also:
apt-get install inotify-tools ## instala em debian (para o esqueleto 2
cpan Linux::Inotify2 ## instala módulo me perl (esqueleto 1)
man inotifywait inotifywatch Linux::Inotify2
You can use the inotifywait to monitor.
– stderr