5.1.4 编写监控脚本并加载到后台执行
[root@inotify-master scripts]# cat inotify.sh 
#!/bin/bash 
#para 
host01=192.168.1.160  #inotify-slave的ip地址 
src=/backup/        #本地监控的目录 
dst=backup         #inotify-slave的rsync服务的模块名 
user=rsync_backup      #inotify-slave的rsync服务的虚拟用户 
rsync_passfile=/etc/rsync.password   #本地调用rsync服务的密码文件 
inotify_home=/usr/local/inotify-3.14    #inotify的安装目录 
#judge 
if [ ! -e "$src" ] \ 
|| [ ! -e "${rsync_passfile}" ] \ 
|| [ ! -e "${inotify_home}/bin/inotifywait" ] \ 
|| [ ! -e "/usr/bin/rsync" ]; 
then 
echo "Check File and Folder" 
exit 9 
fi 
${inotify_home}/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write,delete,create,attrib $src \ 
| while read file 
do 
#  rsync -avzP --delete --timeout=100 --password-file=${rsync_passfile} $src $user@$host01::$dst >/dev/null 2>&1 
cd $src && rsync -aruz -R --delete ./  --timeout=100 $user@$host01::$dst --password-file=${rsync_passfile} >/dev/null 2>&1 
done 
exit 0 
[root@inotify-master scripts]# sh inotify.sh &  #将脚本加入后台执行 
[1] 13438 
[root@inotify-master scripts]#
5.1.5 实时同步测试
 
 inotify-master操作:
[root@inotify-master scripts]# cd /backup/ 
[root@inotify-master backup]# ll 
总用量 0 
[root@inotify-master backup]# for a in `seq 200`;do touch $a;done  #创建200个文件 
[root@inotify-master backup]# ll  --time-style=full-iso 
总用量 0 
-rw-r--r-- 1 root root 0 2014-04-22 15:34:08.141497569 +0800 1 
-rw-r--r-- 1 root root 0 2014-04-22 15:34:08.172497529 +0800 10 
-rw-r--r-- 1 root root 0 2014-04-22 15:34:08.235497529 +0800 100 
-rw-r--r-- 1 root root 0 2014-04-22 15:34:08.236497529 +0800 101 
-rw-r--r-- 1 root root 0 2014-04-22 15:34:08.237497529 +0800 102 
...................................
inotify-slave检查
[root@inotify-slave backup]# ll  --time-style=full-iso 
总用量 0 
-rw-r--r--. 1 rsync rsync 0 2014-04-22 15:34:08.393823754 +0800 1 
-rw-r--r--. 1 rsync rsync 0 2014-04-22 15:34:08.393823754 +0800 10 
-rw-r--r--. 1 rsync rsync 0 2014-04-22 15:34:08.393823754 +0800 100 
-rw-r--r--. 1 rsync rsync 0 2014-04-22 15:34:08.393823754 +0800 101 
-rw-r--r--. 1 rsync rsync 0 2014-04-22 15:34:08.393823754 +0800 102 
..........................

