#!/bin/bash
#1.参数个数
if [ $# -lt 1 ]
then
echo NOT Enough Arguement!!!
exit;
fi
#2.遍历所有机器
for host in sh1 sh2 sh3
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