Unison+inotify-tools实现Ubuntu主机间的多机触发式双向同步

 

安装OpenSSH

 

       在各台服务器上安装OpenSSH,使用如下命令:

       sudo apt-get install openssh

       该命令在你的机器上同时安装了SSH Server和SSH Client。

安装Unison

       在各个需要同步的服务器上执行以下命令安装unison:

sudo apt-get install unison

安装Inotify tools

在各个需要同步的服务器上执行以下命令安装inotify-tools:

       apt-get install inotify-tools

 

 

 

UNISON=`ps -ef |grep -v grep|grep -c inotifywait`

if [ ${UNISON} -lt 1 ]
then
#ip2="192.168.1.7"
src2="/home/hedy/src/"
dst2="/home/hedy/target/"
/usr/bin/inotifywait -mrq -e create,delete,modify,move $src2 | while read line
do
#/usr/local/bin/unison -batch $src2 ssh://$ip2/$dst2
/usr/bin/unison -batch $src2 $dst2
echo -n "$line " >> /home/hedy/log/inotify/inotify$(date +%u).log
echo ` date +%F\ %T " " -f1-4` >> /home/hedy/log/inotify/inotify$(date +%u).log
done
fi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值