1, after the installation of Inotify-tools, the/usr/local/bin directory will be a new generation of inotifywait and inotifywatch two instructions;
Inotifywait: Used to wait for a specific event;
Inotifywatch: used to collect monitored file system statistics, including the number of inferior information per inotify event;
The common options for the inotifywait command are as follows:
-M is to keep listening
-R is a recursive view directory
-Q is the print out event
-e <event>,--event <event> Specifies the specific events that need to be monitored, and all file events are monitored by default;
--timefmt <fmt> when using%t in the--format option, the--TIMEFRT option can be used to specify a custom time format that conforms to the strftime specification; the usual parameters after--timefrt are '%d/%m/%y%h:%m ' ;
--format <fmt> custom inotifywait output format, such as--format '%T%w%f '; the usual format characters are as follows:
%T: Use the custom time format in the--TIMEFMT option;
%w: Displays the file name of the monitored files;
%f: If the object of an event is a directory, the name of the monitored directory is displayed, and the default display is an empty string;
2,vim inotify.sh
#!/bin/bash
Src= "/opt/pub"
Dst= "/opt/share"
/opt/app/inotify/bin/inotifywait-mrq--timefmt '%d/%m/%y%h:%m '--format '%T%w%f '-e modify,delete,create,attrib,move $SRC | While read file
Do
Rsync-avzp--delete $src/$DST/
echo "$file was rsynced" >> Rsync.log 2>&1
Done
This article is from the "Linuxdream" blog, make sure to keep this source http://books.blog.51cto.com/2600359/1598957
Real-time synchronization of rsync+inotify data