Shell脚本:分发文件到各个集群节点

找一个全局目录/root/bin 写脚本

javascript 复制代码
touch xsync
chmod 777 xsync
javascript 复制代码
#!/bin/bash

#作者:ldj
#时间:2024-10-15
#描述:拷贝文件

#1. 判断参数个数
if [ $# -lt 1 ]
    then
       echo "Error: Not Enough Argument!"
       exit
fi

#2.遍历集群所有机器
space=">>>>>>>  "
slash="/"
host_arr=(hadoop10 hadoop11 hadoop12)

for host in ${host_arr[@]}
do	
	#3.获取参数列表(文件)
	for file in $@
	do
	    #4.文件是否存在
	    if [ -e $file ]
		    then
		        #5.当前文件父se目录
		        pdir=$(cd -P $(dirname $file); pwd)
			    #6.当前文件名称
			    fname=$(basename $file)
			    echo $pdir$slash$fname$space$host
				
			    ssh $host "mkdir -p $pdir"
		        rsync -av $pdir/$fname $host:$pdir
		    else
		        echo $file does not exists!
	    fi
	done
done

1.从Window 直接拷贝到Linux可能会报错:/bin/bash^M: bad interpreter: No such file or directory

执行脚本前先 执行

javascript 复制代码
sed -i 's/\r$//' xsync

2.还有一个注意配置域名解析 (重启生效)

相关推荐
大路谈数字化11 分钟前
Centos中内存CPU硬盘的查询
linux·运维·centos
luoqice1 小时前
linux下查看 UDP Server 端口的启用情况
linux
倔强的石头_2 小时前
【Linux指南】动静态库与链接机制:从原理到实践
linux
赏点剩饭7782 小时前
linux中的hostpath卷、nfs卷以及静态持久卷的区别
linux·运维·服务器
神鸟云3 小时前
DELL服务器 R系列 IPMI的配置
linux·运维·服务器·网络·边缘计算·pcdn
herderl3 小时前
**僵尸进程(Zombie Process)** 和**孤儿进程(Orphan Process)**
linux·运维·服务器·网络·网络协议
tomelrg3 小时前
多台服务器批量发布arcgisserver服务并缓存切片
服务器·python·arcgis
lepton_yang3 小时前
Zephyr下控制ESP32S3的GPIO口
linux·嵌入式硬件·esp32·zephyr
泽02023 小时前
Linux 编译器 gcc 与 g++
linux·运维·服务器