shell 同步脚本

来源:互联网 发布:ni数据采集卡如何使用 编辑:程序博客网 时间:2024/06/16 13:11

shell不是很熟,备份一下代码。


#! /bin/bashtransfer(){    rsync -avz -e "ssh -i /home/xxxx/.ssh/id_rsa" $1 $2}if [ $# -lt 1 ]then    echo "Usage: $0 path" 1>&2    exit 1fipath=$1if [ -d $path ]then    path="$path/"fifile="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命令可参考:

http://www.linuxany.com/archives/226.html