首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >期望脚本不识别“--更多--”,之后不会运行任何命令。

期望脚本不识别“--更多--”,之后不会运行任何命令。
EN

Stack Overflow用户
提问于 2015-04-06 11:37:23
回答 1查看 259关注 0票数 2

我正在编写一个expect脚本来自动安装SO磷。看上去是这样的:

代码语言:javascript
复制
#!/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脚本时,它输入许可证的击键,但是当第一个“--更多--”提示符出现时,它什么也不做,并且没有运行后续命令。有什么想法?想法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-06 13:30:02

您是否期望程序依次查看这些模式中的每一个?如果是这样的话,您需要使用多个顺序的expect命令和发送命令:

代码语言:javascript
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29470506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档