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
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
-
-
-
UOS arm换源
清华源mv/etc/apt/sources.list /etc/apt/sources.list.bak备份原始...
[阅读全文]
-
-
IT基础与云计算
软路由器(IPtable)iptable是Linux上常用的防火墙软件。负载均衡负载均衡是网络基础构架的关键组件...
[阅读全文]
-
-
嵌入式行业职位分析
嵌入式开发涵盖硬件软件,开发链条很长,要根据自己的实际情况选择适应的职位。嵌入式的职位大概有:1、硬件工程师:负...
[阅读全文]
-
网友评论