linux shell脚本 远程批量复制文件到各节点

linux | 2019-09-13 10:02:39

写了个linux脚本 可以复制文件到各个节点服务器,方便服务器管理

1.新建脚本文件

touch batchFile.sh


2.scp循环复制文件到服务器脚本


#!/bin/bash
list="slave1 slave2 slave3 slave4"  
for i in $list  
do  
if [ "$1" == "copy" ]
then
scp -r $2 root@$i:$3
echo "finished $i $1 to $2"
fi
 
done
echo "all finished"


3.脚本授权

chmod 777 batchFile.sh


4.执行测试脚本

# ./batchFile.sh copy /opt/hadoop/hbase-1.4.9/conf/hbase-env.sh /opt/hadoop/hbase-1.4.9/conf/
hbase-env.sh                                                                                                                                                                   100% 7532     2.8MB/s   00:00    
finished slave1 copy to /opt/hadoop/hbase-1.4.9/conf/hbase-env.sh
hbase-env.sh                                                                                                                                                                   100% 7532   885.4KB/s   00:00    
finished slave2 copy to /opt/hadoop/hbase-1.4.9/conf/hbase-env.sh
hbase-env.sh                                                                                                                                                                   100% 7532   784.4KB/s   00:00    
finished slave3 copy to /opt/hadoop/hbase-1.4.9/conf/hbase-env.sh
hbase-env.sh                                                                                                                                                                   100% 7532     2.1MB/s   00:00    
finished slave4 copy to /opt/hadoop/hbase-1.4.9/conf/hbase-env.sh
all finished


注意:# ./batchFile.sh copy /opt/hadoop/hbase-1.4.9/conf/hbase-env.sh /opt/hadoop/hbase-1.4.9/conf/

scp第一个参数 指定具体要传输的目录,而第二个参数指定父级目录 ,就可以替换文件

登录后即可回复 登录 | 注册
    
关注编程学问公众号