Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use expect to automatically detect and restart programs on another server

Shulou Source: shulou.com Published: 2022-06-03 06:51:47 09月10日 Update

This article mainly shows you "how to use expect to achieve automatic detection and restart another server on the program", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to use expect to achieve automatic detection and restart another server on the program" this article.

[s005 you] # cat haproxy_expect

The code is as follows:

#! / 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

The code is as follows:

#! / 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

The code is as follows:

#! / 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

The above is all the contents of the article "how to use expect to automatically detect and restart programs on another server". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Servers programs services testing code content articles learning help easy to understand more organization knowledge editing industry information information channels channels research Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Information MariaDB Xiaomi Apple