我正在编写一个expect脚本来自动安装SO磷。看上去是这样的:
#!/usr/bin/expect
set installdir [lindex $argv 0]
set timeout 20
spawn "./install.sh"
expect {
sleep 5
"Press <return> to display Licence. Then press <spc> to scroll forward." {send "\r"}
-ex "--More--" {send -- " "; exp_continue}
"Do you accept the licence? Yes(Y)/No(N)\\\[N\\\]" {send "Y"}
"Where do you want to install Sophos Anti-Virus? \\\[/opt/sophos-av\\\]" {"send $installdir/sophos-av"}
"Do you want to enable on-access scanning? Yes(Y)/No(N) \\\[Y\\\]" {"send \r"}
"Do you want to enable remote management? Yes(Y)/No(N) \\\[Y\\\]" {"send \r"}
"Username for Sophos Anti-Virus GUI? \\\[admin\\\]" {"send \r"}
"Password for Sophos Anti-Virus GUI?" {"********"}
"Re-enter the same password." {"********"}
}
interact当我运行expect脚本时,它输入许可证的击键,但是当第一个“--更多--”提示符出现时,它什么也不做,并且没有运行后续命令。有什么想法?想法?
发布于 2015-04-06 13:30:02
您是否期望程序依次查看这些模式中的每一个?如果是这样的话,您需要使用多个顺序的expect命令和发送命令:
sleep 5
expect "Press <return> to display Licence. Then press <spc> to scroll forward."
send "\r"
expect {
-ex "--More--" {send -- " "; exp_continue}
"Do you accept the licence? Yes(Y)/No(N)\\\[N\\\]"
}
send "Y"
expect "Where do you want to install Sophos Anti-Virus? \\\[/opt/sophos-av\\\]"
send "$installdir/sophos-av\r"
expect "Do you want to enable on-access scanning? Yes(Y)/No(N) \\\[Y\\\]"
send "\r"
expect "Do you want to enable remote management? Yes(Y)/No(N) \\\[Y\\\]"
send "\r"
expect "Username for Sophos Anti-Virus GUI? \\\[admin\\\]"
send "\r"
expect "Password for Sophos Anti-Virus GUI?"
send "********\r"
expect "Re-enter the same password."
send "********\r"
interact一旦expect执行了一个"action“块,expect命令就会返回。除非您告诉它,否则它不会在等待匹配其他模式时出现(exp_continue)
有用的提示:在开发expect脚本时,打开脚本顶部附近的详细调试输出:exp_internal 1。
https://stackoverflow.com/questions/29470506
复制相似问题