expect自动检测并重启另外一台服务器上的程序代码
expect自动检测并重启另外一台服务器上的程序代码
发布时间:2016-12-28 来源:查字典编辑
摘要:[s005you]#cathaproxy_expect复制代码代码如下:#!/usr/bin/expectsetssh_user"fivet...

[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

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新linuxshell学习
热门linuxshell学习
脚本专栏子分类