Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1695060
  • 博文数量: 362
  • 博客积分: 10587
  • 博客等级: 上将
  • 技术积分: 4098
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-10 18:15
文章分类

全部博文(362)

文章存档

2014年(1)

2013年(58)

2011年(115)

2010年(112)

2009年(76)

分类: LINUX

2011-05-26 21:05:15

Server005 tmp # 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
Server005 tmp #





Server004 tmp # 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
Server004 tmp #


Server004 tmp # 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
Server004 tmp #

阅读(693) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~