安装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