Linux 工具

  • 集群节点同步镜像同步目录
#!/bin/bash
#定义集群节点
nodes=(bd-centos01 bd-centos02 bd-centos03)
#需要同步的目录
paths=$@
if [ $# -lt 1 ]
then
    echo input the paths to be synchronized
    exit;
fi
#遍历节点
for host in ${nodes[@]}
do
    echo ================ $host ===================
    # 遍历录入的路径
    for path in $paths
    do
        if [ -e $path ]
        then
            pdir=$(cd -P $(dirname $path); pwd)
            fname=$(basename $path)
            # 创建父级目录,同步路径
            ssh $host "mkdir -p $pdir"
            rsync -av $pdir/$fname $host:$pdir
        else
            echo $path does not exists!
        fi
    done
done

你可能感兴趣的:(#,Linux,linux,运维,服务器)