As @qmechanik very wisely suggested, inotify-utils
is an excellent
starting point for this situation. They allow programs to be activated when the file / directory changes.
Below are two program skeletons (one in perl other in bash) where you can easily grate 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 just using shell \ cite { link }:
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