Linux一键分发文件、应用等

微服务环境部署时,几十台机器需要部署系统,编写文件传输脚本如下.
默认读取同级目录下的data_list.conf 传输配置文件
Linux需要安装依赖软件Tcl、expect. 
#!/bin/bash
data_list="data_list.conf"

if [ "$1" != "" ];then
  data_list="$1"
fi

echo "开始时间:"`date "+%Y-%m-%d %H:%M:%S"`
cat $data_list | while read ip user pass sfile tdir
do
  #echo "IP is $ip"
  #echo "USER is $user"
  #echo "PASS is $pass"
  #echo "SFILE is $sfile"
  #echo "TDIR is $tdir"
  #echo \"command is : scp -r "$sfile" "$user"@"$ip":"$tdir"\"
 #sup_sfile=$(echo -e "${sfile}" | awk -F '\\|' '{print $0}')
  if [[ $sfile =~ '|' ]];then
    path="${sfile%%|*}"
    #echo "path is $path"
    sup_sfile="$(echo -e "${sfile#*|}" | sed 's/|/ /g' )"
    for s_sfile in $sup_sfile
    do
        #echo "s_sfile is $path$s_sfile"
        /usr/bin/expect -c "
          set timeout 3;
          spawn ssh -f -o StrictHostKeyChecking=no "$user"@"$ip" mkdir -p "$tdir"
          expect {
            \"(yes/no)?\" { send \"yes\r\";exp_continue }
            \"*ssword:\" { send \"$pass\r\";exp_continue }
          }
          spawn scp -r "$path$s_sfile" "$user"@"$ip":"$tdir"
          expect {
            \"(yes/no)?\" { send \"yes\r\";exp_continue }
            \"*ssword:\" { send \"$pass\r\";exp_continue }
          }
        
        "
        sleep 1
    done
  else
    sup_sfile="$(echo -e "${sfile}" | sed 's/|/ /g' )"
    for s_sfile in $sup_sfile
    do
        #echo "s_sfile is $s_sfile"
        /usr/bin/expect -c "
          set timeout 3;
          spawn ssh -f -o StrictHostKeyChecking=no "$user"@"$ip" mkdir -p "$tdir"
          expect {
            \"(yes/no)?\" { send \"yes\r\";exp_continue }
            \"*ssword:\" { send \"$pass\r\";exp_continue }
          }
          spawn scp -r "$s_sfile" "$user"@"$ip":"$tdir"
          expect {
            \"(yes/no)?\" { send \"yes\r\";exp_continue }
            \"*ssword:\" { send \"$pass\r\";exp_continue }
          }
        
        " 
        sleep 1
    done
  fi 
done  
echo "结束时间:"`date "+%Y-%m-%d %H:%M:%S"`

配置文件如下 data_list.conf
也可以自行定义多个conf文件,执行shell时进行指定参数即可

10.11.149.42 tomcat Edxd@123 /app/tomcat/scms/easyloan/system-springboot-1.0.0-SNAPSHOT.jar|/app/tomcat/scms/easyloan/spring-boot.sh|/app/tomcat/scms/easyloan/startall.sh|/app/tomcat/scms/easyloan/stopall.sh|/app/tomcat/scms/easyloan/rules|/app/tomcat/scms/easyloan/kettle|/app/tomcat/scms/easyloan/template|/app/tomcat/scms/easyloan/writeList.properties /app/tomcat/scms/easyloan
10.11.149.51 tomcat Edxd@123 /app/tomcat/scms/easyloan/dataApplication-springboot-1.0.0-SNAPSHOT.jar|/app/tomcat/scms/easyloan/spring-boot.sh|/app/tomcat/scms/easyloan/startall.sh|/app/tomcat/scms/easyloan/stopall.sh|/app/tomcat/scms/easyloan/rules|/app/tomcat/scms/easyloan/kettle|/app/tomcat/scms/easyloan/template /app/tomcat/scms/easyloan
10.11.149.52 tomcat Edxd@123 /app/tomcat/scms/easyloan/dataApplication-springboot-1.0.0-SNAPSHOT.jar|/app/tomcat/scms/easyloan/spring-boot.sh|/app/tomcat/scms/easyloan/startall.sh|/app/tomcat/scms/easyloan/stopall.sh|/app/tomcat/scms/easyloan/rules|/app/tomcat/scms/easyloan/kettle|/app/tomcat/scms/easyloan/template /app/tomcat/scms/easyloan
10.11.149.61 tomcat Edxd@123 /app/tomcat/scms/easyloan/afterloan-springboot-1.0.0-SNAPSHOT.jar|/app/tomcat/scms/easyloan/spring-boot.sh
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值