Monday, November 4, 2024

pre-post check script

 #######################################################
#!/bin/ksh
# set the DB env and run
# Script to check PRE & Post checks Manually
#
# CB - <Date>   - version 1 - Initial Draft
#set -x

echo -e "\n*************************************"
echo  "DATE = `date`"
echo  "HOSTNAME = " `hostname`
echo -e "*************************************\n"

if [ "$1" = "" ]; then
  echo -e "\n please Provide pre or post "
  echo -e "Syntax: $0 <pre>|<post> \n"
  exit 1
elif [[ "${chk_type}" == "pre" || "${chk_type}" == "post" ]]; then
  echo -e "\n Entered ${chk_type}   ..........  \n"
else
  echo -e "\n Please enter either " PRE " or " POST " Only. \n"
  exit 1
fi

chk_type=`echo $1 | tr "[:upper:]" "[:lower:]"`
export logfile=/home/oracle/CB/${chk_type}_shell_logfile.log
export home=<ORACLE_HOME>
export oem_agent_home=<Agent_home>
export psu_location=<Patch_path>/<patch#>

#exit 1
precheck(){
echo -e "\n   -----[ Gather OS Info ]------\n"
date
uname -a
cat /etc/oratab
ps -ef |grep pmon
ps -ef |grep tns
crsctl stat res -t
df -h
echo -e "\n   -----[ OEM Agent Info ]------\n"
${oem_agent_home}/bin/emctl status agent
${oem_agent_home}/bin/emctl status blackout <name>
}


home_check () {
echo -e "\n     -----[ Gather PATCH Info ]------\n"
$home/OPatch/opatch version
$home/OPatch/opatch lsinventory
 if [[ "$chk_type" == "pre" ]]; then
  echo -e "\n Checking patch Conflicts ........."
  cd ${psu_location}
  ${home}/OPatch/opatch prereq CheckConflictAgainstOHWithDetail -ph ./
 fi
}

db_check () {
echo -e "\n   -----[ Gather DB Info ]------\n"
crsctl stat res -t | grep ".db$" |tr "." " " | awk -F" " '{print $2}'| while read LINE2
do
 # case $LINE2 in
 #   *)
echo -e "\n Running for : $LINE2  "
srvctl status database -d $LINE2 -v
srvctl status service -d $LINE2 -v
echo "-------------------------"
#esac
done
}

home_check | tee -a ${logfile}
precheck | tee ${logfile}
db_check  | tee -a ${logfile}

sql_info (){
cat /etc/oratab | grep 112|tr ":" " "  | awk -F" " '{print $1}' |egrep -v ''\#'|ASM' | while read LINE3
do
export ORACLE_SID=${LINE3}
export ORACLE_HOME=${home}
export LD_LIBRARY_PATH=$ORACLE_HOME/bin:$PATH
#echo "$LINE3"
echo -e "\n    --------[ Running for database : $LINE3 ]---------"
$ORACLE_HOME/bin/sqlplus -s / as sysdba << eof
set pages 999 lines 280 feedback off
col COMMENTS for a33
col pdb_name format a15
col dp_action format a15
col dp_status format a20
col dp_action_time format a20
col dp_description format a30
select comments, action, to_char(action_time,'DD/MM/RR HH24:MI:SS') action_date, version  from sys.registry\$history  order by action_date;
 select name,action_time dp_action_time,id dp_patch_id,action dp_action,comments dp_description from v\$database,sys.registry\$history  where action_time=(select max(action_time)   from sys.registry\$history);
eof
done
}

sql_info

cat  ${logfile} | mailx -s "`hostname` : precheck info " Your_email

 
Auto Scroll Stop Scroll