我有兩個腳本,或者最好將一個腳本稱為另一個腳本的包裝器。
這是包裝器:
#!/usr/bin/expect
set timeout 20
spawn "./installOracleDatabase.sh"
expect "replace Disk1/upgrade/gen_inst.sql?" { send "N\r" }
expect "Specify the HTTP port that will be used for Oracle Application Express" { send "\r" }
expect "Specify a port that will be used for the database listener" { send "\r" }
expect "initial configuration:" { send "root\r" }
expect "Confirm the password:" { send "root\r" }
expect "Do you want Oracle Database 11g Express Edition to be started on boot" { send "y\r" }
這是主要腳本:
#!/bin/bash
#install required libraries and programs
sudo yum -y install libaio bc flex unzip
#unzipping the Oracle package
unzip -q oracle-xe-11.2.0-1.0.x86_64.rpm.zip
cd Disk1
sudo rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm
sudo /etc/init.d/oracle-xe configure
cat " . /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh" >> $HOME/.bashrc
第二個腳本的問題是,在 的最後一步之後sudo /etc/init.d/oracle-xe configure
,當設定腳本詢問「您希望 Oracle (...) 在引導時啟動」時,就在該步驟之後,在正常安裝過程中,Oracle 是執行其他一些步驟:
Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]:y
Starting Oracle Net Listener...Done
Configuring database...Done
Starting Oracle Database 11g Express Edition instance...Done
Installation completed successfully.
這一步需要一些時間。但我的腳本在回答y
最後一個問題後立即退出...
如何強制腳本等待整個配置完成?
答案1
為了使腳本等到Oracle最後一步,您可以嘗試將以下行新增至腳本expect
末尾expect
expect "Starting Oracle Net Listener...Done" { send "\r" }
expect "Configuring database...Done" { send "\r" }
expect "Starting Oracle Database 11g Express Edition instance...Done" { send "\r" }
expect "Installation completed successfully." { send "\r" }
expect eof