生成新进程并返回到Expect脚本

4
我正在使用Expect脚本自动安装程序。由于某个安装依赖项存在问题,我需要在特定点暂停安装过程以编辑 db.properties 文件。一旦更改了该文件,就可以恢复安装过程。我可以在安装中间生成一个新进程来完成这个操作,但是在关闭该进程后,我会遇到 "spawn id exp5 not open" 错误。
db_edit.sh 能够编辑适当的文件:
#!/usr/bin/sh
filename=db.properties
sed -i "s/<some_regex>/<new_db_info>/g" $filename

我的自动化安装脚本在执行过程中生成了上述脚本:

#!/usr/bin/expect

# Run the installer and log the output
spawn ./install.bin
log_file install_output.log

# Answer installer questions
# for simplicity, let's pretend there is only one
expect "PRESS <ENTER> TO CONTINUE:"
send "\r"

# Now I need to pause the installation and edit that file
spawn ./db_edit.sh
set db_edit_ID $spawn_id
close -i $db_edit_ID
send_log "DONE"

# Database Connection - the following must happen AFTER the db_edit script runs
expect "Hostname (Default: ):"
send "my_host.com\r"
# more connection info ...

expect eof

输出日志install_output.log显示以下错误:
PRESS <ENTER> TO CONTINUE: spawn ./db_edit.sh^M
DONEexpect: spawn id exp5 not open
    while executing
"expect "Hostname (Default: ):""^M

数据库信息已经被正确修改,因此我知道脚本可以工作并且确实已经生成。然而,当我关闭该进程时,安装进程的生成 ID 也显然被关闭,这会导致“spawn id exp5 not open”错误。
另外值得注意的是,生成似乎发生在应该之前。对于“PRESS <ENTER>”的响应应该是“\r”或“^M”,以表示已发送“ENTER”。
如何修复这个问题,以便在关闭“db_edit.sh”后恢复安装脚本?
1个回答

2

不需要使用spawn自动化与该脚本的任何交互。

exec db_edit.sh

这样,您就不会干扰当前生成进程的spawn_id。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接