linux expect 即exp脚本交互功能【原】

时间:2023-03-09 05:46:37
linux expect 即exp脚本交互功能【原】

场景

expect命令用于任何自动化互动的过程。

  • send – 发送字符串到进程
  • expect – 等待来自进程的特定的字符串
  • spawn – 启动命令

安装

expect一开始100%不存在, 手动执行yum安装

yum install expect

使用入门

假如有文件如下 /tmp/helloworld.exp

expect "hello" {
send "world\n"
}

执行 expect  /tmp/helloworld.exp

将会进入交互模式, 直到你按了hello+换行后,输出world 再退出交互模式.

参考

6个Expect脚本示例==>https://blog.****.net/robertsong2004/article/details/38983259