linux的分发脚本
程序员文章站
2024-02-26 16:02:16
...
linux的分发脚本
#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]
then
echo Not Enough Arguement!
exit;
fi
#2. 遍历所有目录,挨个发送
for file in [email protected]
do
#4.5 判断文件是否存在
if [ -e $file ]
then
#3. 获取父目录 -P直接指向实际物理地址 防止软链接
pdir=$(cd -P $(dirname $file); pwd)
#4. 获取当前文件的名称
fname=$(basename $file)
#5. 遍历集群所有机器,拷贝,cluster是一个写有所有主机名的文件,如果没有配置主机映射 ,此处需要写各个主机的地址
for host in $(cat /opt/module/cluster)
do
echo ==================== $host ====================
rsync -av $pdir/$fname [email protected]$host:$pdir
done
else
echo $file does not exists!
fi
done
下一篇: Java按时间梯度实现异步回调接口的方法