shell不是很熟,备份一下代码。
#! /bin/bash
transfer()
{
rsync -avz -e "ssh -i /home/xxxx/.ssh/id_rsa" $1 $2
}
if [ $# -lt 1 ]
then
echo "Usage: $0 path" 1>&2
exit 1
fi
path=$1
if [ -d $path ]
then
path="$path/"
fi
file="conf/nodes.lst"
for node in `cat $file`
do
echo "Transfer to $node ..."
transfer $path "$node:~/$path"
done
===================================
脚本用法:
conf/nodes.lst ==> 需要同步的机器列表
需要传入一个需要被同步的文件,l例如
./sync.sh files/file1.txt
rsync命令可参考: