欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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