问题描述
以下脚本是可以的,但是必须在需要帮助的情况下进行修改,或者在我必须发送负载平衡期望值的地方提出建议,如果启用,是的,那么我必须提供第二个节点的IP地址,我不知道该如何设置条件,请您帮忙?
#!/usr/bin/expect
set timeout 2
spawn "./config.sh"
expect "Your choice:" { send "1\r" } expect "Do you want to select network (y/n)" { send "y\r" } expect "Please enter an address for the interface" { send "$env(IP)\r" } expect "Please enter the default gateway address" { send "$env(GW_IP)\r" } expect "Is this server" { send "y\r" } expect "Address range for the private network" { send "$env(PRIV_subnet)\r" } expect "Do you want to enable loadbalancing" { send "n\r" } expect "Please do you confirm (y/n):" { send "y\r" } expect "Do you want to clear the current configuration (first configuration)" { send "y\r" } expect "file already exist,do you want to replace it" { send "y\r" }
interact
解决方法
如果这是您的实际代码,那么您需要将每个expect
命令放在其自己的行上(或用分号分隔)。
尝试一下:
#!/usr/bin/expect
# This is for debugging. Remove or comment when you're finished testing.
exp_internal 1
spawn "./config.sh"
set timeout 2
expect_before timeout {
puts "Timeout! Exiting"
exit 1
}
expect "Your choice:" {send "1\r"}
expect "Do you want to select network (y/n)" {send "y\r"}
expect "Please enter an address for the interface" {send "$env(IP)\r"}
expect "Please enter the default gateway address" {send "$env(GW_IP)\r"}
expect "Is this server" {send "y\r"}
expect "Address range for the private network" {send "$env(PRIV_SUBNET)\r"}
expect "Do you want to enable loadbalancing" {send "n\r"}
expect "Please do you confirm (y/n):" {send "y\r"}
expect "Do you want to clear the current configuration (first configuration)" {send "y\r"}
expect "file already exist,do you want to replace it" {send "y\r"}
interact