2022
我们一起努力

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

[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

本文从互联网转载,来源地址:www.downzz.com/linux-shell/171698.html,原作者保留一切权利,若侵权或引用不当,请联系茶猫云(cmy.cn)删除。【茶猫云,优质云服务器提供商】

赞(0)
文章名称:《expect自动检测并重启另外一台服务器上的程序代码》
文章链接:https://www.fzvps.com/34985.html
本站文章来源于互联网,如有侵权,请联系管理删除,本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
图片版权归属各自创作者所有,图片水印出于防止被无耻之徒盗取劳动成果的目的。

评论 抢沙发

评论前必须登录!