我正在编写一个期望脚本来自动化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--”提示符出现时不执行任何操作,并且不运行后续命令。思考?想法?
答案 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
。