Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report