#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]
then
echo Not Enough Arguement!
exit;
fi
#2. 遍历集群所有机器
rpm -q rsync &>/dev/null || yum install -y rsync
for host in es01 es02 es03
do
echo ==================== $host ====================
#3. 遍历所有目录,挨个发送
for file in $@
do
#4. 判断文件是否存在
if [ -e $file ]
then
#5. 获取父目录
pdir=$(cd -P $(dirname $file); pwd)
#6. 获取当前文件的名称
fname=$(basename $file)
ssh $host "mkdir -p $pdir"
#7. 判断远程主机是否安装了rsync命令
ssh $host "rpm -q rsync &>/dev/null || yum install -y rsync"
rsync -av $pdir/$fname $host:$pdir
else
echo $file does not exists!
fi
done
done
标签:脚本,rsync,同步,pdir,echo,host,done,file
From: https://www.cnblogs.com/jubian520/p/17165208.html