Folder monitoring on Linux

Asked

Viewed 622 times

0

I could use some help. I need to assemble a shell script monitor 4 folders where each one receives a file with template different from the other.

I need that when the file arrives an e-mail be sent to me. I am new in shell and found nothing on the net.

Suggestions?

1 answer

2


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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.