rsync + inotify script

#!/bin/sh

chkconfig: 2345 10 90

description: This Rsync script based on inotify.

date: 2019-04-08

version: 1.0

Path src1 = / test # monitoring
des1 = uploaders / # rsync module name to that need to be synchronized on the server
rsync_passwd_file = / etc / server.pass # password Interchange File
ip = 192.168.8.178 # the need to synchronize IP
the User = Yihong # need to synchronize the user side
the inotify = / usr / bin / the inotifywait
CD srcl} $ {
$ --timefmt the inotify -mrq '% Y-% M-% D% H:% M' --format '%% W T F% E% '--event Modify, Create, Move, Delete, Attrib ./ | File Read the while
do
INO_EVENT = $ (echo $ File | awk' Print $ {}. 4 ')
INO_FILE = $ (echo $ File | awk' {Print . 3} $ ')
echo "------------------------- $ (DATE) --------------- ----------------------- ">> /var/log/rsync.log 2>. 1 &
echo >> $ File / var / log / rsync.log 2> &. 1
IF [[$ INO_EVENT = 'the CREATE ']] || [[$ INO_EVENT =' MODIFY ']] || [[$ INO_EVENT =' CLOSE_WRITE ']]||[[ $INO_EVENT='MOVED_TO' ]];then
echo 'CREATE or MODIFY or CLOSE_WRITE or MOVED_TO' >> /var/log/rsync.log 2>&1
rsync -avzcR $(dirname ${INO_FILE}) ${user}@${ip}::${des1} --password-file=${rsync_passwd_file} >>/var/log/rsync.log 2>&1
fi
if [[ $INO_EVENT='DELETE' ]]||[[ $INO_EVENT='MOVED_FROM' ]];then
echo 'DELETE or MOVED_FROM' >>/var/log/rsync.log 2>&1
rsync -avzR --delete $(dirname ${INO_FILE}) ${user}@${ip}::${des1} --password-file=${rsync_passwd_file}>>/var/log/rsync.log 2>&1
fi
if [[ $INO_EVENT='ATTRIB' ]];then
echo 'ATTRIB' >>/var/log/rsync.log 2>&1
if [ ! -d "$INO_FILE" ];then
rsync -avzcR $(dirname ${INO_FILE}) ${user}@${ip}::${des1} --password-file=${rsync_passwd_file}>>/var/log/rsync.log 2>&1
fi
fi
done&

Guess you like

Origin blog.51cto.com/13746824/2438847