以前经常通过一个定时脚本实现文件同步,隔断时间检查一下,但总感觉这个不太智能化,于是一顿考量,选择了强大的 inotifywait,废话少说看代码
yum install inotify-tools
grep INOTIFY_USER /boot/config-$(uname -r)
如果输出是 CONFIG_INOTIFY_USER=y
代表可以#!/bin/sh
# get the current path
CURPATH=`pwd`
ip="`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`"
inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' \
-e modify -e create -e delete -e move -e attrib /mnt/fzdisk/sync/var/www/ | while read date time dir file; do
rsync -a --delete /mnt/fzdisk/sync/var/www /root/t/var/ && \
echo " $ip At ${date} ${time} www files was rsync" >> /mnt/fzdisk/log/$ip.log
done
用法很简单:
好了,具体参数你可以网上继续搜索一下,很多的
deepxl 11月 16th, 2017
Posted In: computer knowledge(电脑知识)