转 测试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

原文地址:https://www.cnblogs.com/feiyun8616/p/7782366.html