找一个全局目录/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.还有一个注意配置域名解析 (重启生效)


