liunx集群文件分发脚本xsync

[root@node-etl-01 bin]# yum install rsync -y
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 10:53:14 ago on Mon Nov  1 09:17:41 2021.
Dependencies resolved.
=====================================================================================================================================================
 Package                          Architecture                      Version                                  Repository                         Size
=====================================================================================================================================================
Installing:
 rsync                            x86_64                            3.1.3-12.el8                             baseos                            405 k

Transaction Summary
=====================================================================================================================================================
Install  1 Package

Total download size: 405 k
Installed size: 819 k
Downloading Packages:
rsync-3.1.3-12.el8.x86_64.rpm                                                                                        372 kB/s | 405 kB     00:01    
-----------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                253 kB/s | 405 kB     00:01     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                             1/1 
  Installing       : rsync-3.1.3-12.el8.x86_64                                                                                                   1/1 
  Running scriptlet: rsync-3.1.3-12.el8.x86_64                                                                                                   1/1 
  Verifying        : rsync-3.1.3-12.el8.x86_64                                                                                                   1/1 

Installed:
  rsync-3.1.3-12.el8.x86_64                                                                                                                          

Complete!
[root@node-etl-01 bin]# cd /root
[root@node-etl-01 ~]# mkdir bin
[root@node-etl-01 bin]# cat xsync
#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]
then
  echo Not Enough Arguement!
  exit;
fi

#2 获取当前用户名
user=$(whoami)


#3. 遍历集群所有机器
for((host=1; host<=3; host++))
do
  echo ====================  node-etl-0$host  ====================
  #4. 遍历所有目录,挨个发送
  for file in $@
  do
    #5 判断文件是否存在
    if [ -e $file ]
    then
      #6. 获取父目录
      pdir=$(cd -P $(dirname $file); pwd)
      #7. 获取当前文件的名称
      fname=$(basename $file)
      ssh $user@node-etl-0$host "mkdir -p $pdir"
      rsync -av $pdir/$fname $user@node-etl-0$host:$pdir
    else
      echo $file does not exists!
    fi
  done
done
[root@node-etl-01 bin]# chmod +x xsync
[root@node-etl-01 bin]# xsync xsync
==================== node-etl-01 ====================
sending incremental file list

sent 44 bytes  received 12 bytes  112.00 bytes/sec
total size is 695  speedup is 12.41
==================== node-etl-02 ====================
sending incremental file list
xsync

sent 786 bytes  received 35 bytes  1,642.00 bytes/sec
total size is 695  speedup is 0.85
==================== node-etl-03 ====================
sending incremental file list
xsync

sent 786 bytes  received 35 bytes  1,642.00 bytes/sec
total size is 695  speedup is 0.85

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值