2017-06-15 63 views
-1

我正在编写一个脚本来自动安装ambari服务器。 我在tcl脚本上创建了自动化ambari-server设置。我的问题是在一个地方下载并安装jdk,并且该步骤需要一点时间,同时另一个预期的其他发送会在屏幕上弹出,并将所有安装完成。TCL中两个期望之间的延迟

我的脚本:

#!/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" 

接受甲骨文二进制代码许可协议后,下载并安装JDK并在这期间它开始服用发送下节选的。

有人可以建议我如何停止除前一个仍在运行的执行。 我曾尝试使用后,睡觉尝试的东西,但它没有奏效。 谢谢

+0

为什么会有人downvote呢?为什么这不是一个足够好的问题?我确实分享了我的代码,我写了我所尝试的。如果你在付出这么多努力的时候善意地留下了为什么你这么做的理由。 –

+0

我发现一个临时修复通过把设置超时足够长的时间来安装jdk。如果仍然有人可以提出更好的解决方案,那将非常棒。 –

+0

可以在下载和安装jdk进行和结束时显示安装sctipt的输出吗? – komar

回答

0

改变timeout是正确的做法。我会写:

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" 
0

如果未收到预期的字符串,您的代码缺少处理程序的操作。添加这些将是一种很好的风格。否则,正如你所看到的那样,如果字符串没有在分配的时间内被接收(默认为10秒),脚本将继续。

要为一个expect命令使用不同的超时值,可以简单地使用-timeout选项。例如,允许10分钟的jdk安装:

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" 
    } 
}