• jenkins_ssh


    实现shell结构体数组

    实现expect和ssh, scp

    #!/bin/bash
    
    # 参考: https://stackoverflow.com/questions/15684646/array-like-data-structure-in-bash-config-file
    # 参考: https://blog.csdn.net/yuesichiu/article/details/17245089
    
    declare -A box2032=([ip]=192.168.20.32 [port]=22 [pwd]=aaa [posidas]=/opt/dass/dasserver)
    declare -A box2028=([ip]=192.168.20.28 [port]=22 [pwd]=aa [posidas]=/opt/dass/dasserver)
    declare -A box2048=([ip]=192.168.20.48 [port]=22 [pwd]=aaa [posidas]=/root/dasserver)
    declare -A box50135=([ip]=192.168.50.135 [port]=2233 [pwd]=aaa [posidas]=/root/dasserver)
    
    declare -a boxs=(box2032 box2028 box2048 box50135)
    
    cd ..
    
    for ((i=0; i<${#boxs[@]}; i++))
    do
    {
    box=${boxs[$i]}
    ip=$box[ip]
    port=$box[port]
    pwd=$box[pwd]
    posi=$box[posidas]
    
    # 发送命令删除老旧文件命令
    /usr/bin/expect <<-EOF
    
    set timeout -1
    spawn ssh -p ${!port} root@${!ip}
    expect {
    "*yes/no" { send "yes\r"; exp_continue }
    "*password:" { send "${!pwd}\r" }
    }
    
    expect "#*"
    send "rm -rf /home/mhx\r"
    send "mkdir -p /home/mhx\r"
    send "exit\r"
    
    expect eof
    EOF
    
    
    # 发送文件
    /usr/bin/expect <<-EOF
    
    set timeout -1
    # 注意下面是大写的P
    spawn scp -P ${!port} ./dasserver root@${!ip}:/home/mhx
    expect {
    "*yes/no" { send "yes\r"; exp_continue }
    "*password:" { send "${!pwd}\r" }
    }
    
    expect eof
    EOF
    
    # 发送命令,替换可执行程序
    /usr/bin/expect <<-EOF
    
    set timeout -1
    spawn ssh -p ${!port} root@${!ip}
    expect {
    "*yes/no" { send "yes\r"; exp_continue }
    "*password:" { send "${!pwd}\r" }
    }
    
    
    expect "#*"
    send "rm -rf ${!posi}/dasserver\r"
    expect "#"
    send "cp -r  /home/mhx/dasserver ${!posi}/dasserver\r"
    send "chmod 777 ${!posi}/dasserver\r"
    send "pkill dasserver\r"
    send "exit\r"
    
    expect eof
    EOF
    
    } &
    done
    
    wait 
    
    echo "大盒子全部ok"
    
  • 相关阅读:
    【案例】图片上传
    BOM相关知识点
    【案例】图片无缝轮播效果
    DOM相关知识点
    【案例】雪花飘落效果
    DOM节点克隆
    DOM节点的创建、插入、删除
    【案例】列表全选、全不选、反选
    AJAX相关概念及应用
    解决跨域问题
  • 原文地址:https://www.cnblogs.com/maomaomaoge/p/15743696.html
Copyright © 2020-2023  润新知