«

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

时间:2024-3-2 15:46     作者:韩俊     分类: Linux


[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

标签: linux

热门推荐