2016-07-22 74 views
3

我正在使用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 

數據庫信息已被正確修改,所以我知道該腳本的作品,它確實催生了。但是,當我關閉該過程時,安裝過程的產卵編號也顯然已關閉,導致出現spawn id exp5 not open錯誤。

另外好奇的是,產卵似乎發生在它應該之前。對"PRESS <ENTER>"的迴應應爲"\r"^M以指示發送了ENTER

如何解決此問題以在關閉db_edit.sh後恢復安裝腳本?

回答

2

沒有必要自動化與該腳本任何交互,所以不要使用spawn

exec db_edit.sh 

這樣,你不與當前衍生進程的spawn_id在干擾。