上传到不同服务器脚本

一个分片上传的脚本:

#!/bin/sh

source ./shard.properties

for i in {0..7}
do
    echo "[`date`] scp $i start"

    targetUrlPath=`eval echo '$'"shard${i}"`


    host=$(echo $targetUrlPath|awk -F ':' '{print $1}')
    targetPath=$(echo $targetUrlPath|awk -F ':' '{print $2}')
    uploadPath=`eval echo $targetPath|awk -F '/'  '{newPath=substr($0,0,length($0)-length($(NF-1))-1);print newPath"bak";}'`
    remoteCmd=`eval echo mkdir -p $uploadPath`
 
       ssh $host   `eval echo $remoteCmd`
       
    scp -o StrictHostKeyChecking=no -l 400000 externalhour/shard/${i}/external_adproduct  ${host}:${uploadPath}/.


    remoteMvCmd=`eval echo mv  ${uploadPath}/external_adproduct ${targetPath}external_adproduct`
    echo ${remoteMvCmd}
    ssh $host   "${remoteMvCmd}"
    

    echo "[`date`] mv  end"
done

分片配置文件:

shard0=xx.xx.xx.xx:/home/search/data0/
shard1=xx.xx.xx.xx:/home/search/data0/
shard2=xx.xx.xx.xx:/home/search/data0/
shard3=xx.xx.xx.xx:/home/search/data0/
shard4=xx.xx.xx.xx:/home/search/data0/
shard5=xx.xx.xx.xx:/home/search/data0/
shard6=xx.xx.xx.xx:/home/search/data0/
shard7=xx.xx.xx.xx:/home/search/data0/


服务器文件为ip列表:

172.1.1.1
172.1.1.2
172.1.1.3
地址固定,可这么写 :

#!/bin/sh


fileName=xx

for line in `cat ips.txt` 
do
	host=$line
	echo $line

    targetPath="~/xx/solr/xx/"
	uploadPath="~/xx/solr/xx/bak/"
	remoteCmd=`eval echo mkdir -p $uploadPath`
	
    ssh $host   `eval echo $remoteCmd`
    echo ${targetPath}   
    scp -o StrictHostKeyChecking=no -l 400000 ${fileName}  ${host}:${uploadPath}/
	for i in {1..100}
	do
    	remoteMvCmd=`eval echo cp  ${uploadPath}/${fileName} ${targetPath}shard${i}/${fileName}`
    	ssh $host   "${remoteMvCmd}"
    	echo "[`date`] cp  end"
	done  
done

文/程忠 浏览次数:0次   2020-07-20 21:44:02

相关阅读


评论: