我已经登录了CUCM,然后我们尝试执行一个命令,该命令是正确的,但根据预期值,我们无法执行第二个命令。首先,我们这样做:
send -i $install_id "utils ctl set-cluster mixed-mode\r\n"
puts "we are hitting yes &&&&&&&&&&"
expect {
-i $install_id -re ".*" {
send -i $install_id "y\r"
puts "$$$$$$$$$$$$$$$ we are inside...."
}
}
puts "we are done %%%%%%%%%%"
return 1在这里,第一个命令send -i $install_id "utils ctl set-cluster mixed-mode\r\n"可以成功执行,但它不会进入expect循环。
第一个命令的输出类似于:-
admin:utils ctl set-cluster mixed-mode
This operation will set the cluster to Mixed mode. Do you want to continue? (y/n):在此之后,光标将位于下一行,在那里我必须给出y和enter,expect中的输出语句也不会打印出来
发布于 2016-08-23 18:12:17
我会做类似这样的事情:
expect {
-i $install_id
-ex "continue? (y/n):" {
puts "I FOUND A CONTINUE PROMPT"
send -i $install_id "y\r"
exp_continue
}
"$thePrompt" {
puts "I FOUND A SYSTEM PROMPT"
}
}这样,它只会在命令完成后停止该expect,但它会响应continue提示并继续运行(因为exp_continue)。在这种情况下,-ex选项是合适的,因为它匹配文字字符串,当您要查找的内容包含多个正则表达式元字符(?、(和))时,这是非常方便的。
当然,将"$thePrompt"更改为与提示符实际匹配的内容。
https://stackoverflow.com/questions/39095700
复制相似问题