expect自动检测并重启另外一台服务器上的程序代码

本站所有内容来自互联网收集,仅供学习和交流,请勿用于商业用途。如有侵权、不妥之处,请第一时间联系我们删除!Q群:迪思分享

免费资源网 – https://freexyz.cn/

[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 “yesr” }

sleep 0.5

expect “Enter passphrase for key*”

send “$passwordr”

expect “*#”

send “/tmp/haproxy.shr”

expect “*#”

send “echor”

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 “yesr” }

sleep 0.5

expect “Enter passphrase for key*”

send “$passwordr”

expect “*#”

send “/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfgr”

expect “*#”

send “echor”

exit

免费资源网 – https://freexyz.cn/


© 版权声明
THE END
★喜欢这篇文章吗?喜欢的话,麻烦动动手指支持一下!★
点赞5 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容