集群分发脚本

#!/bin/bash

# 判断参数格式
if [ $# -lt 1 ]
then
    echo '参数数量不对'
    exit;
fi
# 遍历集群所有机器
for host in host01 host02 host03
do
    echo =============== $host ================
    # 遍历所有目录,挨个发送
    for file in $@
    do
        # 判断文件是否存在
        if [ -e $file ]
        then
            # 获取父目录 
            pdir=$(cd -P $(dirname $file); pwd) 
            # 获取当前文件的名称 
            fname=$(basename $file) 
            ssh $host "mkdir -p $pdir" 
            rsync -av $pdir/$fname $host:$pdir 
        else 
            echo $file does not exists! 
        fi 
    done 
done

保存为脚本后记得添加执行权限

chmod +x xsync 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×