Linux xsync命令脚本

功能:在主机上分发文件到其他机器

在主机machine136上进行如下操作(master)

1、安装 rsync

yum install -y rsync

2、bin下创建 xsync

转自:(82条消息) Linux xsync命令脚本_hunheidaode的博客-CSDN博客_linux xsync

复制代码
#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]
then
 echo Not Enough Arguement!
 exit;
fi
 
#2. 遍历集群所有机器
for host in machine136 machine137 machine138
do
 echo ==================== $host ====================
 #3. 遍历所有目录,挨个发送
 for file in $@
 do
 #4. 判断文件是否存在
 if [ -e $file ]
 then
 #5. 获取父目录
 pdir=$(cd -P $(dirname $file); pwd)
 #6. 获取当前文件的名称
 fname=$(basename $file)
 ssh $host "mkdir -p $pdir"
 rsync -av $pdir/$fname $host:$pdir
 else
 echo $file does not exists!
 fi
 done
done
复制代码

3、给脚本赋予执行权限 

chmod  777 xsync

4、vi /etc/hosts

192.168.1.136 machine136
192.168.1.137 machine137
192.168.1.138 machine138

5、执行测试 machine136上执行

xsnyc test

 

根据提示输入 machine137 machine138密码 后,同步完成。

登录到137,138 查看目录已经完成同步

 

posted on   hztech  阅读(136)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示