5.hadoop3 xsync 脚本

1.

linux 软链接

[atguigu@hadoop102 ~]$ ln -s aaa bbb

[atguigu@hadoop102 ~]$ cd -P bbb

-P的理解  就是为了防止软链接问题  直接找到根目录

尝试在写一层   软链接

[atguigu@hadoop102 ~]$ ln -s bbb ccc

[atguigu@hadoop102 ~]$ cd -P ccc

直接到aaa

[atguigu@hadoop102 aaa]$ pwd
/home/atguigu/aaa
 

删除软链接比较安全的方式

[atguigu@hadoop102 ~]$ pwd
/home/atguigu
[atguigu@hadoop102 ~]$ unlink ccc
[atguigu@hadoop102 ~]$ ll

2.basename命令

[atguigu@hadoop102 ~]$ basename a.txt
a.txt
[atguigu@hadoop102 ~]$
[atguigu@hadoop102 ~]$ basename  /home/atguigu/a.txt
a.txt
[atguigu@hadoop102 ~]$

3.总的图片信息

-p 的理解   如果文件夹存在就覆盖

4.102上同步一个 bin文件

102上  /home/atguigu

执行

xsync bin/

103和104都能看到同步的 bin

104

分发环境变量信息

[atguigu@hadoop102 ~]$ xsync /etc/profile.d/my_env.sh 错误吧

环境变量一般是root

[atguigu@hadoop102 ~]$ sudo ./bin/xsync /etc/profile.d/my_env.sh

检验103 和104

104

具体的脚本如下:

#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]
then
 echo Not Enough Arguement!
 exit;
fi
#2. 遍历集群所有机器
for host in hadoop102 hadoop103 hadoop104
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
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值