本Shell用于实时检测当前文件下的文件是否有更新,如果有则同步到其它服务器上
#! /bin/bash
KEY='/root/.ssh/id_rsa'
PORT=22
SSH_OPT=" -i $KEY -p $PORT"
CUR_DIR=`pwd`
//要保持同步的服务器IP,可以添加多个:
DST_IPS=('102.152.138.28');
//要同步的文件
FILES=('a.txt'
'b.txt'
'dir/dir1/c.txt'
)
# Check the file last change time
function getLastChangeTime()
{
time=`stat $1 | grep Change | awk '{print $3}'`
echo "$time"
}
# Distribute the new files to all servers
function sendToServers()
{
for ip in ${DST_IPS[*]}
do
strCount=`echo $1 | tr -cd '/' | wc -c `
dstDir=`echo $1 | cut -d '/' -f 1-$strCount`
# file=`echo $1 | cut -d '/' -f $strCount`