2

I have created a script to shutdown Oracle database but unable to send the output of shutdown while the database shutdown completes successfully. I only receive email of the echo part but not the actual part of shutdown. I want to capture the output of shutdown and send it via mailx to my emailid.

Also let me know how to capture this log in HTML format and send it via emailid.

LOG_FILE="Shutdown_of_$ORACLE_SID_`hostname`_Completed_`date "+%Y_%b_%d"`.txt"   
echo "">>$LOG_FILE  
echo "">>$LOG_FILE  
echo " =========================================================  ">>$LOG_FILE
echo "">>$LOG_FILE
echo " Step  : SHUTTING Down of database                          ">>$LOG_FILE  
echo " Start : `date `                                            ">>$LOG_FILE    
echo " ========================================================   ">>$LOG_FILE

echo "">>$LOG_FILE  
echo "">>$LOG_FILE  

export SHUT=/home/oracle/SHUT.txt  
>$SHUT  
sqlplus -s / as sysdba << EOF  
set feedback off verify off termout off linesize 120 pagesize 500;  
spool $SHUT  
shut immediate;  
spool off;  
exit;  
EOF  

echo "">>$LOG_FILE  
echo " =========================================      "  >>$LOG_FILE
echo " Status : Completed                             ">>$LOG_FILE
echo " End   : `date`                                 ">>$LOG_FILE
echo " =========================================      ">>$LOG_FILE
echo "">>$LOG_FILE

mailx -s "Shutdown_of_'$ORACLE_SID'_`hostname`_Completed_`date "+%Y_%b_%d"` " [email protected]  < $LOG_FILE

NOTE: My Bash version: GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu).

1 Answer 1

2

I generally do what you want like this:

#!/bin/bash

{
cat <<-EOF


 =========================================================  

 Step  : SHUTTING Down of database                          
 Start : `date `                                            
 ========================================================   



EOF

export SHUT=/home/oracle/SHUT.txt  
>$SHUT 

sqlplus -s / as sysdba <<-EOF  
set feedback off verify off termout off linesize 120 pagesize 500;  
spool $SHUT  
shut immediate;  
spool off;  
exit;  
EOF

cat $SHUT

cat <<-EOF

 =========================================
 Status : Completed
 End    : $(date)
 =========================================

EOF

} | mailx -s "Shutdown_of_'$ORACLE_SID'_$(hostname)_Completed_$(date "+%Y_%b_%d") " \
      [email protected]

The above creates a subshell which will capture all the output from the commands within it. We then pipe all this output to mailx directly.

NOTE: Pay special attention to any additional spacing around the EOF markers when using heredocs. An errant extra space at the end of the EOF can lead to it not working.

References

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .