Linux分发文件xsync

在Linux集群中工作时,配置文件时需要分发文件的时候用scp比较耗时间;

此时需要编辑一个分发的shell脚本来分发文件. 

#!/bin/bash
pcount=$#
if [ $pcount -lt 1 ]
then
    echo Not Enough Arguement!
    exit;
fi
# 这里改成你的主机名,n个
for host in node01 node02 node03
do
    echo ====================    $host    ====================
    for file in $@
    do
        if [ -e $file ]
        then
            pdir=$(cd -P $(dirname $file); pwd)
            echo pdir=$pdir
            fname=$(basename $file)
            echo fname=$fname
            ssh $host "mkdir -p $pdir"
            rsync -av $pdir/$fname $USER@$host:$pdir
        else
            echo $file does not exists!
        fi
    done
done

需要让这个文件获得最高权限:

chmod  777  xsync

如果需要全局可用,将本文件编辑后将其放置到  /bin 文件中

原文地址:https://www.cnblogs.com/joey-413/p/13952789.html