Appearance
安装依赖
yum install -y automake安装
推送端安装 inotify
wget https://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
tar -xzvf inotify-tools-3.14.tar.gz
cd ./inotify-tools-3.14
./configure --prefix=/usr/local/inotify
make && make install启动
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %w%f %e' -e close_write,modify,delete,create,attrib,move //usr/local/nginx/html/
参数
inotify常用参数
| 参数 |含义
| -r |递归查询目录
| -q |打印很少的信息,仅仅打印监控事件信息
| -m |始终保持事件监听状态
| --excludei |排除文件或目录时,不区分大小写
| --timefmt |指定事件输出格式
| --format |打印使用指定的输出类似格式字符串
| -e |通过此参数可以指定要监控的事件
access 文件或目录被读取 modify 文件或目录的内容被修改 attrib 文件或目录属性被改变 close 文件或目录封闭,无论读/写模式。 open 文件或目录被打开 move_tomove 文件或目录被移动至另外一个目录 文件或目录被移动另一个目录或从另一个目录移动至当前目录 create 文件或目录被创建在当前目录 delete 文件或目录被删除 umount 文件系统被卸载
自动化脚本
touch rsync.sh
chmod 777 rsync.shshell
#!/bin/bash
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f %e' -e close_write,modify,delete,create,attrib,move /usr/local/nginx/html/ | while read file
do
rsync -az --delete --password-file=/etc/rsyncd.pwd.client /usr/local/nginx/html/ foo@192.168.44.102::ftp/
done