Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  shell  >  正文 expect自动检测并重启另外一台服务器上的程序

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

发布时间:2014-09-27   编辑:www.jquerycn.cn
expect自动检测并重启另外一台服务器上的程序的代码,有需要的朋友可以参考下。[s005 you] # cat haproxy_expect

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

您可能感兴趣的文章:
expect自动检测并重启另外一台服务器上的程序
expect自动登录远程服务器和执行重复任务的例子
expect批量管理计算机的一个脚本
expect脚本远程批量管理服务器的思路解析
用expect实现ssh自动登录服务器并进行批量管理
shell结合expect写的批量scp脚本工具
一个远程登录的简单expect脚本
自动登录到多台服务器的shell脚本
实现ssh自动登录的4种方法
mysql主从复制配置与原理分析

[关闭]