“This is the 11th day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021”
I. Occurrence of problems:
Recently, I was writing a script to implement single-click ORACLE 11G/12C/18C/19C standalone installation and build a library script (shell). During the test of 11G and 12C, I encountered a problem. When executing the installation command:
runInstaller -silent -force -ignoreSysPrereqs -responseFile ${SOFTWAREDIR}/db.rsp -ignorePrereq
Copy the code
The installation process does not wait until the installation is complete. Instead, the installation process enters the background process and executes the next command. As a result, the installation fails.
Ii. Thinking and solving:
To this end, I have come up with several solutions:
1. Expec interactive command to monitor, too troublesome, failed to put into practice.
2. Read -p to add a message indicating that the installation is successful and press Enter to continue.
if [ "${DB_VERSION}" = "11.2.0.4"] | | ["${DB_VERSION}" = "12.2.0.1" ]; then
echo "Oracle Software Install Starting......"
echo
echo
sleep 20
echo
echo
echo "When Successfully Setup Software Apper. Then Press Enter continue."
echo
echo
read -p "Please Don't Press Enter. Now Waiting..........."
echo
fi
Copy the code
Cons: This method is simple to implement, but it defeats my intention of fully automatic script.
3. Write a log, and then run the grep loop to obtain the log every 5 seconds while do. When the log is Successfully Setup Software, break exits and continue to perform the next step.
su - oracle -c "${SOFTWAREDIR}/database/runInstaller -silent -force -ignoreSysPrereqs -responseFile ${SOFTWAREDIR}/db.rsp -ignorePrereq" >>${SOFTWAREDIR}/setupDatabase.out
echo
echo
sleep 20
echo "Oracle Software Install Starting......"
echo
echo
while true; do
echo -n "."
sleep 5s
grep "Successfully Setup Software" ${SOFTWAREDIR}/setupDatabase.out >>/dev/null
if [ $? -eq 0 ]; then
echo
echo
c1 "Successfully Setup Software." blue
break
fi
done
Copy the code
Disadvantages: This method is automated and can be executed successfully. However, the installation log cannot be output to the console, because it is written into the log. If the installation fails, there is no way to know, and the loop will continue indefinitely. You need to manually check the installation log setupDatabase.out to determine whether the installation is successful, which is not straightforward.
4. After the above thinking, I just need to implement, while entering the log to the log, without affecting the console output, so I thought of the tee command, modify 3 script:
su - oracle -c "${SOFTWAREDIR}/database/runInstaller -silent -force -ignoreSysPrereqs -responseFile ${SOFTWAREDIR}/db.rsp -ignorePrereq" | tee ${SOFTWAREDIR}/setupDatabase.out
while true; do
echo -n "."
sleep 5s
grep "Successfully Setup Software" ${SOFTWAREDIR}/setupDatabase.out >>/dev/null
if [ $? -eq 0 ]; then
echo
echo
c1 "Successfully Setup Software." blue
break
fi
done
Copy the code
In the result test, I was surprised to find that while judged that it was executed after the installation command was successfully executed, so I continued to modify the script as:
if [[ "${DB_VERSION}" = "12.2.0.1"[[]] | |"${DB_VERSION}" = "11.2.0.4"]].then
su - oracle -c "${SOFTWAREDIR}/database/runInstaller -silent -force -ignoreSysPrereqs -responseFile ${SOFTWAREDIR}/db.rsp -ignorePrereq" |tee ${SOFTWAREDIR}/setupDatabase.out
rm -rf ${SOFTWAREDIR}/setupDatabase.out
fi
Copy the code
The test continues. The command is executed successfully and the installation is complete. The installation result is as follows:
The flowers are angry (° °) Blue ✿, celebrate!!
From this, it can be inferred that: tee command can prevent the program background running.