expect自动检测并重启另外一台服务器上的程序代码
更新时间:2013年02月09日 19:46:37 作者:
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
相关文章
linux shell中 if else以及大于、小于、等于逻辑表达式介绍
在linux shell编程中,大多数情况下,可以使用测试命令来对条件进行测试,这里简单的介绍下,方便需要的朋友2013-02-02
ssh(ssh-keygen)配置免输入密码登录远程主机的方法
这篇文章主要是介绍ssh(ssh-keygen)配置免输入密码登录远程主机的方法,供大家学习参考2013-02-02
编写Bash Shell通过gnuplot绘制系统性能数据图的方法
这篇文章主要介绍了编写Bash Shell通过gnuplot绘制系统性能数据图的方法,做到可视化数据收集,需要的朋友可以参考下2015-07-07


最新评论