oracledba.help
Scripts

DBA Script

<- Scripts

#!/bin/bash
# Purpose:      Run SQL Command
# Version:      2018.10.01
# Dependencies: inc_system.sh

######################################
# Preamble: 2018.10.01               #
######################################
set -a; DIR_SCRIPTS="/u01/app/scripts"; source $DIR_SCRIPTS/inc_system.sh
sFullName=$(basename "$0"); me=${sFullName%.*}
sSLog="$DIR_LOGS/$me.sess.log"; sHLog="$DIR_LOGS/$me.hist.log"; > $sSLog
if [[ $MAINT_WINDOW -eq 1 ]]; then printf "Maintenance Window Detected - Exiting\n"; exit; fi

# User Vars
usrSQLPlusInit="SET ECHO ON"
usrConnString="connect BI/DQlOjb8eRXpVRel!@DNASOLO"
usrCmd="EXEC dbms_mview.refresh('BI.MV_CONTACTINFORMATION', method=>'C', atomic_refresh=>false);"


######################################
# Start                              #
######################################
clear; log "$sSLog" "$sFullName Started"; linesep
SysVars_show

# Init
log "$sSLog" "Init"
nRnd=$(shuf -i100-999 -n1)
fScript="$DIR_TMP/$me.$nRnd.tmp";
fSpool="$DIR_TMP/$me.$nRnd.spool";

# Create Script
log "$sSLog" "Create Script"
cat > $fScript <<-EOF
 $usrSQLPlusInit
 $usrConnString
 spool $fSpool
 $usrCmd
 spool off
 exit
EOF

# Run Script
log "$sSLog" "Running Script"
CMD="`$ORACLE_HOME/bin/sqlplus / as sysdba @$fScript $fSpool`";
cat $fSpool >> $sSLog

# Housekeeping
log "$sSLog" "Housekeeping"
rm $fScript
rm $fSpool


######################################
# End                                #
######################################
log "$sSLog" "$sFullName Ended [Elapse Time: $(elapse)]";
echo $(linesep "=") >> $sHLog; cat $sSLog >> $sHLog;
tail -32768 $sHLog > $sHLog.tmp; mv $sHLog.tmp $sHLog