【发布时间】:2014-11-18 09:52:10
【问题描述】:
我正在使用expect 脚本来安装一些软件包。在这样的安装过程中,有时它会要求权限说Y/n 来安装它们,有时它不会。
我有两个问题:
1 ) 如何处理这两种情况?
#!/usr/bin/expect --
# This is for boto libraries installation
spawn apt-get install python-pip
expect {
"Do you want to continue"
{ send "Y\r\n" ## HERE SOMETIMES THIS STRING MAY NOT APPEAR
}
}
interact
spawn pip install filechunkio
interact
spawn pip install -U boto
interact
当期望字符串没有出现时,它会抛出错误
spawn_id: spawn id exp6 not open
while executing
"interact"
(file "./botoInstall.exp" line 10)
第 10 行是第一个交互。
2 ) spawn_id: spawn id exp6 not open 是什么意思?
【问题讨论】:
-
在没有这些混乱的情况下,将
-y传递给apt-get是否不能满足您的要求?至少对于apt-get步骤。 -
对于 1) 见 Dinesh 的回答。对于 2),这是因为没有出现预期的字符串,所以
expect命令只会在timeout或eof上返回。由于apt-get命令通常会很快完成(expect 命令会看到eof,这意味着生成的apt-get进程已经退出,所以interact命令肯定会失败。