期望脚本无法识别“--MORE--”,之后没有运行任何命令

时间:2015-04-06 11:37:24

标签: install expect

我正在编写一个期望脚本来自动化Sophos安装。这是它的样子:

#!/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脚本时,它会输入许可证的击键,但在第一个“--MORE--”提示符出现时不执行任何操作,并且不运行后续命令。思考?想法?

1 个答案:

答案 0 :(得分:0)

您是否希望程序依次查看每种模式?如果需要,您需要使用多个顺序期望和发送命令:

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执行&#34;操作&#34;阻止,expect命令将返回。除非你告诉它(exp_continue

,它不会等待匹配其他模式

有用的提示:在开发expect脚本时,打开脚本顶部附近的详细调试输出:exp_internal 1

相关问题