• 企业400电话
  • 网络优化推广
  • AI电话机器人
  • 呼叫中心
  • 全 部 栏 目

    网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    expect自动检测并重启另外一台服务器上的程序代码
    POST TIME:2021-10-18 16:45

    [s005 you] # cat haproxy_expect

    复制代码 代码如下:

    #!/usr/bin/expect
    set ssh_user "fivetrees"
    set password "123456"
    spawn ssh -i /root/.ssh/$ssh_user Server004.xd.com
    expect_before "no)?" {
    send "yes\r" }
    sleep 0.5
    expect "Enter passphrase for key*"
    send "$password\r"
    expect "*#"
    send "/tmp/haproxy.sh\r"
    expect "*#"
    send "echo\r"
    exit

    [s004 him] # cat haproxy.sh

    复制代码 代码如下:

    #!/bin/bash
    Thread=`ps -ef | grep haproxy | grep -v haproxy.sh | grep -v grep`
    if [ -z "$Thread" ]
    then
            /tmp/haproxy_expect
    fi

    [s004 him] # cat haproxy_expect

    复制代码 代码如下:

    #!/usr/bin/expect
    set ssh_user "fivetrees"
    set password "123456"
    spawn ssh -i /root/.ssh/$ssh_user Server005.xd.com
    expect_before "no)?" {
    send "yes\r" }
    sleep 0.5
    expect "Enter passphrase for key*"
    send "$password\r"
    expect "*#"
    send "/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg\r"
    expect "*#"
    send "echo\r"
    exit

    上一篇:查看某时间段到现在的系统日志的sed命令
    下一篇:shell查找当前目录下大于1M的文件的三种方法分享
  • 相关文章
  • 

    关于我们 | 付款方式 | 荣誉资质 | 业务提交 | 代理合作


    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    X

    截屏,微信识别二维码

    微信号:veteran88

    (点击微信号复制,添加好友)

     打开微信