I am writing a script to automate the ambari server installation. I have created on tcl script to automate ambari-server setup. My issue is at one place it downloads and installs jdk and that step takes a little time and meanwhile the other sends under other expects starts popping up on screen and screws up all the installation.
My Script:
#!/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"
after accepting Oracle Binary Code License Agreement it downloads and installs jdk and in that duration it starts taking send of next excepts.
Can someone suggest me how to stop the execution of an except while the previous one is still running. i did try to use after and sleep to try something but it did not work. Thanks
答案 0 :(得分: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"
答案 1 :(得分:0)
如果未收到预期的字符串,您的代码将缺少处理程序。添加这些将是一种很好的风格。否则,如果在规定的时间内没有收到字符串(默认为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"
}
}