当前位置: 操作系统/服务器>linux
expect自动检测并重启另外一台服务器上的程序代码
来源: 互联网 发布时间:2014-10-13
本文导语: [s005 you] # cat haproxy_expect 代码如下:#!/usr/bin/expectset ssh_user "fivetrees"set password "123456"spawn ssh -i /root/.ssh/$ssh_user Server004.xd.comexpect_before "no)?" {send "yesr" }sleep 0.5expect "Enter passphrase for key*"send "$passwordr"expect "*#"send "/tmp/haproxy.shr"expect "*#"s...
[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
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。