TCL中两个expect之间的延迟

TCL中两个expect之间的延迟,tcl,expect,Tcl,Expect,我正在编写一个脚本来自动安装ambari服务器。 我已经在tcl脚本上创建了用于自动安装ambari服务器的脚本。我的问题是,它在一个地方下载并安装jdk,这一步需要一点时间,而另一个地方则在屏幕上弹出“其他预期”下发送,并破坏了所有的安装 我的剧本: #!/usr/bin/expect spawn sudo ambari-server setup expect "OK to continue" send "y\r" expect "Customize user account for a

我正在编写一个脚本来自动安装ambari服务器。 我已经在tcl脚本上创建了用于自动安装ambari服务器的脚本。我的问题是,它在一个地方下载并安装jdk,这一步需要一点时间,而另一个地方则在屏幕上弹出“其他预期”下发送,并破坏了所有的安装

我的剧本:

#!/usr/bin/expect

spawn sudo ambari-server setup

expect "OK to continue"
send "y\r"

expect "Customize user account for ambari-server daemon"
send "y\r"

expect "Enter user account for ambari-server daemon (root):"
send "root\r"

expect "Enter choice (1):"
send "1\r"

expect "Do you accept the Oracle Binary Code License Agreement"
send "y\r"

expect"Enter advanced database configuration"
send "y\r"

expect "Enter choice (1):"
send "3\r"

expect "Hostname (localhost):"
send "localhost\r"

expect "Port (3306):"
send "3306\r"

expect "Database name (ambari):"
send "ambari\r"


expect "Username (ambari):"
send "ambari\r"


expect "Enter Database Password (bigdata):"
send "password\r"

expect "Proceed with configuring remote database connection properties"
send "y\r"
在接受Oracle二进制代码许可协议后,它下载并安装jdk,在此期间,它开始发送下一个例外

是否有人可以建议我如何在前一个仍在运行时停止执行Exception。 我确实试着用after和sleep来尝试一些东西,但没有效果。
谢谢

更改
超时
是正确的方法。我会写:

expect "Do you accept the Oracle Binary Code License Agreement"
set old_timeout $timeout    ;# remember the previous value
set timeout -1              ;# disable the timeout
send "y\r"

expect"Enter advanced database configuration"
set timeout $old_timeout    ;# restore the timeout
send "y\r"

您的代码缺少处理程序,用于在未收到预期字符串时执行的操作。这将是一个很好的风格添加这些。否则,如您所见,如果在分配的时间内(默认情况下为10秒)未收到字符串,脚本将继续

要对一个expect命令使用不同的超时,只需使用-timeout选项。例如,允许jdk安装10分钟:

expect -timeout 600 "Enter advanced database configuration"
send "y\r"
并在出现故障时添加处理程序:

expect {
    -timeout 600
    "Enter advanced database configuration" {
        send "y\r"
    }
    default {
        error "jdk failed to install in time"
    }
}

为什么会有人否决这个?为什么这不是一个好问题?我分享了我的代码,写了我尝试过的东西。如果您在向下投票方面投入了这么多精力,请留下这样做的原因。我通过设置足够长的超时时间来安装jdk,找到了一个临时修复方法。如果还有人能提出更好的解决方案,那就太好了。当下载和安装jdk开始和结束时,您能显示安装sctipt的输出吗?