三、shell分发脚本

目录

1 脚本

#! /bin/bash

#判断参数个数
if [ $# -lt 1]
	then
		echo "The arguement is not enough!"
		exit;
fi
#遍历集群所有机器
for host in node01 node02 node03 node04
do
	#遍历所有文件	
	for file in $@
	do
		#判断文件是否存在
		if [ -e $file ] 
			then
				#获取父目录
				pdir=$(cd -P $(dirname $file);pwd);
		                #获取文件名称
				fname=$(basename $file);
				#对目标host创建对应文件
				ssh $host "mkdir -p $pdir";
			        #rsync同步文件
				rsync -av $pdir/$file $host:$pdir/$file;
	    	else
	    		echo "The file $file is not exists!"
	    fi
	done
done
原文地址:https://www.cnblogs.com/nuochengze/p/14585797.html