Monitoring folders in Linux

0

I need some help. I need to mount a shell script that is monitoring 4 folders where each one receives a file with template different from the other one.

I need an e-mail to be sent to me when I get there. I am new to shell and have not found anything on the net.

Suggestions?

    
asked by anonymous 29.04.2015 / 14:43

1 answer

2

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
    
29.04.2015 / 16:39