scp_rsnyc.sh
#! /bin/env bash
set -x
#set -e
################################################################
#$1 函数选项
#$2 源文件/git分支
#$3 目标文件路径
#tee 从标准输入读取并写入标准输出和文件
#V1.2ban 去除;分号,分号的作用位忽略前执行结果执行一个命令
# |_________修改从定向格式 ,重定向元字符前后需要工
###############################################################
sourcefile=$2
dstdir=$3
declare -A host
host=(
["web3"]="¥"
["web4"]="¥"
["web2"]="¥"
)
function ss()
{
for key in $(echo ${!host[@]});
do
echo "开始scp同步$key==>${host[$key]}";
scp -Cprv $sourcefile ${host[$key]}:$dstdir &>> /var/log/batchscp.log;
echo "ststus is $?";
done
}
function sr()
{
for key in $(echo ${!host[@]});
do
echo "开始rsync同步$key==>${host[$key]}";
rsync -artuz $sourcefile ${host[$key]}:${dstdir:=$sourcefile} &>> /var/log/batchrsync.log;
echo "status is $?";
done
}
function sg()
{
git clone -b $sourcefile http://用户:密码6@¥:8800/zh/$dstdir
}
function pull()
{
for key in $(echo ${!host[@]});
do
echo "开始拉取应用日志";
scp -Cprq ${host[$key]}:$sourcefile $dstdir;
echo "status is $?"
done
}
function ssc()
{
for key in $(echo ${!host[@]});
do
echo "开始发送命令$key";
ssh ${host[$key]} "$sourcefile";
echo "$?"
done
}
$1