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

  • 相关阅读:
    SPOJ 4110 Fast Maximum Flow (最大流模板)
    CF 277E Binary Tree on Plane (拆点 + 费用流) (KM也可做)
    POJ 2289 Jamie's Contact Groups (二分+最大流)
    POJ 1723 SOLDIERS (中位数)
    TRI 解题报告
    POJ 2455 Secret Milking Machine (二分 + 最大流)
    POJ 2112 Optimal Milking (二分 + 最大流)
    POJ 2195 Going Home / HDU 1533(最小费用最大流模板)
    POJ 2135 Farm Tour (最小费用最大流模板)
    运维自动化
  • 原文地址:https://www.cnblogs.com/feiyun8616/p/7782366.html
Copyright © 2011-2022 走看看