inotify.sh脚本范例

inotify.sh脚本范例

 
 
 

[root@A-Server58 ~]# cat /server/scripts/inotify.sh
#!/bin/bash
#para
host01=192.168.1.111
src=/dingjian
dst=dingjian
user=rsync_backup
rsync_passfile=/etc/rsync.password
inotify_home=/usr/local/inotify-tools-3.14/

#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

原文地址:https://www.cnblogs.com/L-H-R-X-hehe/p/3960774.html