inotify介绍
inotifywait :真正实现文件监控程序
inotifywatch:数据统计
-m 持续监控(捕捉到一个事件后不退出)
-r 递归监控,包括目录下的子文件
-q 减少屏幕输出(qq全部不输出)
-e 指定监控类别 (midity修改、move移动、create创建、delete删除、attrib属性)
inotify+rsync文件同步
客户端(本地服务器):10.0.0.30
服务端(远程服务器):10.0.0.40
前置条件:inotify安装完成,rsync配置完成
创建脚本文件
使用循环
while
do
done
#!/bin/bash
#
prog="inotifywait"
events="create,delete,modify,attrib"
iopt="-mrq"
lpath="/home/file/" #监控目录
rhost="10.0.0.40" #远程主机
vuser="vuser1" #rsync虚拟用户
secfile="/etc/rsyncd.passwd" #密码文件
ropt="-az"
modName="mod1" #模块名
#监控目录
$prog $iopt --format "%w%f" -e $events $lpath | while read line
do
#echo $line
#sleep 3 测试
rsync $ropt $line $vuser@$rhost::$modName --password-file=$secfile
done