go-Expect-实验

ops/2024/9/23 10:18:54/

实验脚本程序

test.sh

read -p "Would you like to rejoin it to the cluster? [y/N]:" v
echo
if [ "$v" == "y" ];thenecho "$(date +%s)shark A" >> ./test.log
fi
read -p "Would you like to rejoin it to the cluster? [y/N]:" v
if [ "$v" == "y" ];thenecho "$(date +%s)shark B" >> ./test.log
firead -p "Would you like to remove it from the cluster's metadata? [y/N]:" v2
if [ "$v2" == "n" ];thenecho "shark C"
fi
echo "The cluster was successfully rebooted."

go 程序

main.go

package mainimport ("fmt""regexp""time""github.com/google/goexpect"//   "google.golang.org/grpc/codes"
)const (timeout = 10 * time.Second
)func main(){cmd := "sh test.sh"member :=  [1]string{"mysql1"}for _, _ = range member{e, _, err := expect.Spawn(cmd, -1)defer e.Close()ot, err := e.ExpectBatch([]expect.Batcher{&expect.BCas{[]expect.Caser{&expect.Case{R: regexp.MustCompile(`rejoin it to the cluster\? \[y/N]:`), S: "y\n", T:  expect.Next(), Rt: 1},&expect.Case{R: regexp.MustCompile(`rejoin it to the cluster\? \[y/N]:`), S: "y\n", T:  expect.Next(), Rt: 1},&expect.Case{R: regexp.MustCompile(`remove it from the cluster's metadata\? \[y/N]:`), S: "n\n", T: expect.Next(), Rt: 1},&expect.Case{R: regexp.MustCompile(`The cluster was successfully rebooted`), T: expect.OK()},}},}, timeout)fmt.Println("ot:", ot, "err:", err)}
}//&expect.Case{R: regexp.MustCompile(`rejoin it to the cluster\? \[y/N]:`), S: "y\n", T:  expect.Continue(expect.NewStatus(codes.OK, "继续")), Rt: 1},

http://www.ppmy.cn/ops/41149.html

相关文章

深入解析RedisJSON:在Redis中直接处理JSON数据

码到三十五 : 个人主页 JSON已经成为现代应用程序之间数据传输的通用格式。然而,传统的关系型数据库在处理JSON数据时可能会遇到性能瓶颈。为了解决这一问题,Redis推出了RedisJSON模块,它允许开发者在Redis数据库中直接存储、查询…

Swift中的泛型

Swift中的泛型(Generics)是一种编程特性,它允许你编写灵活、可重用的代码,这些代码可以处理多种不同的数据类型,而无需为每个数据类型都编写单独的代码。泛型通过引入类型参数(Type Parameters)…

代码随想录算法训练营第36天|● 738.单调递增的数字 ● 968.监控二叉树

738. 单调递增的数字 发现第一位变小了其他的迅速变9 class Solution:def monotoneIncreasingDigits(self, n: int) -> int:strnlist(str(n))for i in range(len(strn)-1,0,-1):if strn[i-1]>strn[i]:strn[i-1]str(int(strn[i-1])-1)for j in range(i,len(strn)):strn[…

覆冰形状分析

覆冰形状分析 覆冰是一种常见的自然现象,特别是在冬季或高海拔地区。当大气中的过冷却水滴或降水与低于冰点的物体表面接触时,会发生冻结现象,从而形成覆冰。这种覆冰现象在电力系统、航空、建筑等领域中均有所体现,对设施的安全…

面向对象的三大特性是什么?

面向对象编程(Object-Oriented Programming, OOP)是现代软件开发中的核心范式之一,其核心概念在于将现实世界的事物抽象为“对象”,并通过类和对象之间的交互来实现复杂的功能。面向对象的三大特性包括:封装&#xff0…

什么是RSocket?它有哪些优势?

在传统Web应用开发过程中,我们都是基于HTTP协议实现请求-响应式的交互方式。这种交互方案很简单,但不够灵活,也无法应对所有的响应式应用场景。那么,有没有在网络协议层上提供更加丰富的交互方式呢?答案是肯定的&#…

python dict赋值时有逗号自动变成元组 关于str去除\转义replace用\\

webpack 查找n.m时用的加载器是页面上调用的,因为赋值了s等于加载器 s(‘8536’) s.m[‘8536’] headers[Cookie] f_m_h5_tk{cookie_list[0]}; _m_h5_tk_enc{cookie_list[1]}{accept: */*, accept-language: zh-CN,zh;q0.9, cache-control: no-cache, pragma: no-…

Android 屏幕适配全攻略(上)-掌握屏幕单位,应对千变万化的设备

本文从 Android 开发中常见的长度单位 px、dp、sp 入手,详细介绍了它们的特点及转换关系。 接着深入探讨了屏幕尺寸、分辨率、像素密度等重要的屏幕指标,帮助读者全面理解它们之间的联系。最后,通过实例代码演示了如何在代码中进行单位转换&…