Thursday, 14 March 2019

Check whether to patch Oracle OPatch

I was trying to figure out how to script if OPatch needed updating to the minimum required when patching Oracle software.

So I came up with the following.

Set my ORACLE_HOME to the software directory and add OPatch and bin to the PATH

export ORACLE_HOME=/u01/app/oracle/prod/mwwc12213

This is the minimum OPatch version required

export MIN_OP=

This gets the installed OPatch version

opv=$(opatch version | head -1 | cut -f2 -d":" | sed 's/^ *//g') # Returns

And then converts the version number to an array of numbers, splitting on the period

op_ver=(${opv//./ }) # Returns an array - 13 9 3 0 0
op_min=(${MIN_OP//./ }) # Returns an array - 13 9 4 0 0

I then convert each member of the array to a zero padded number and combine to make a 10 digit number

min_total=$(printf "%02d%02d%02d%02d%02d" ${op_min[0]} ${op_min[1]} ${op_min[2]} ${op_min[3]} ${op_min[4]}) # Returns 1309040000
ver_total=$(printf "%02d%02d%02d%02d%02d" ${op_ver[0]} ${op_ver[1]} ${op_ver[2]} ${op_ver[3]} ${op_ver[4]}) # Returns 1309030000

Display a message, either success or failure

if (( $min_total > $ver_total )); then
  echo -e "\nOPatch Version\n~~~~~~~~~~~~~~\nMinimum   : $MIN_OP\nInstalled : $opv\nStatus    : \e[31mFailed - Patch OPatch and retest before continuing.\e[0m\n"
  echo -e "\nOPatch Version\n~~~~~~~~~~~~~~\nMinimum   : $MIN_OP\nInstalled : $opv\nStatus    : \e[32mSuccess - Continue patching.\e[0m\n"

Success message example
OPatch Version
Minimum   :
Installed :
Status    : Success - Continue patching.
Failure message example
OPatch Version
Minimum   :
Installed :
Status    : Failed - Patch OPatch and retest before continuing.
This doesn't stop people ignoring this and continuing without patching but it's an easy way to calculate whether to patch OPatch or not.

No comments:

Post a comment

Oracle CPU downloader

Every quarter I have to go through and download numerous patches for the Oracle CPU (Critical Patch Update). You have to view the CPU docume...