How to monitor Directories for any changes and take some action after the change

Linux-LogoDo you want to replicate your file system after any changes occurred? There is an application named .incron. for this type of work. The incrond (inotify cron daemon) is a daemon which monitors filesystem events (such as add a new file, delete a file and so on) and executes commands or shell scripts. It.s use is generally similar to cron.

How to install incron

Install RHEL EPEL Repo on Centos 5.x or 6.x before installing incron

CentOS 5.x

CentOS 6.x

Type the following command under RHEL / Fedora / CentOS Linux:

Type the following command under Debian / Ubuntu Linux:

To turn On the Service type the following command:

Few examples about usage of incornd service.

Example-1

Type the following command:

Append the following command:

Now we will test our configuration

It works!!

Now, wherever files will change in /root/test1 directory, rsync will be executed to sync files to /root/test2 directory.

Example-2

This command is to check Subdirectories Recursively.

Above command will create a file named recursive.conf in /etc/incron.d/ directory. And the folders listed in the file will rsync automatically.

Below command will display a list of available events

Configuration Files:

You can insert information about the filesystem event into the arguments of the executed command. The documentation file /usr/share/doc/incron-0.5.5/README notes that these substitutions are available:

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
The following two tabs change content below.

Tapas Mishra

Sr. Engineer (DevOps)
Loves to work on Opensource products. Having experience on Linux environment. Knowledge on Public cloud services like AWS, Rackspace, DigitalOcean, Linode. Please don't hesitate to give a comment on the posts. Your comments are my strength.

Leave a Reply