zoukankan      html  css  js  c++  java
  • 转 测试linux中expect的timeout参数的作用

    http://blog.csdn.net/msdnchina/article/details/50638818

    关于timeout 我个人认为单个命令的交互时间,

    expect可以实现自动交互:

      set:设置变量;set timeout -1,永不超时;set timeout 300,300秒后没有expect内容出现退出;

      spawn:想要执行的命令,你想要进行的交互命令;

      expect:等待命令提示信息,交互的过程,系统会给一些输入密码等提示,expect就是抓取其中关键字,当expect抓取到了后面的关键字,就会执行send。

      send:发送信息,完成交互,检测到关键字后向交互界面输入的信息。

      interact:

      expect eof:结束退出;

    以下是个案例,展示软件的自动化安装过程,

    expect <<- EOF
    set timeout 20                                                                                        //默认每个命令的等待超时时间为10秒,这里加大到20秒,防止有些命令执行时间过长
    spawn ./install
    expect "Do you wish to continue? [y,n] (y)"
    send "y "
    expect "Do you want to install the NetBackup client software for this client? [y,n] (y)"
    send "y "
    expect "Enter the name of the NetBackup master server :"
    send "pnbumaster "
    expect "name of the NetBackup client? [y,n] (y)"
    send "y "
    expect "Is this correct? [y,n]"
    send "y "
    set timeout 120                                                                                           //因为接下来的命令运行时间比较长,所以设置这条命令等待事件为120 s
    expect "Enter the authorization token for pnbumaster or q to skip:"
    send "SCSKLNPLQRGDHDDG "
    expect "Enter the authorization token for pnbumaster or q to skip:"         //这里输入最后一个expect 其实多大用,但是我们发现安装过程经常异常退出,加入这一条语句就不会异常退出了
    EOF

  • 相关阅读:
    模块介绍
    homebrew 更改镜像,进行成功安装
    必须要会的 50 个 React 面试题
    聚合
    mongodb高级聚合查询
    一款好用 mongodb 可视化工具
    在Mac上安装MongoDB,配置全局路径
    深入Vue2.x的虚拟DOM diff原理
    H5在WebView上开发小结
    接口文档RAP2 环境搭建(正常搭建成功)
  • 原文地址:https://www.cnblogs.com/feiyun8616/p/7782366.html
Copyright © 2011-2022 走看看