捕获 HTML 格式的日志并通过电子邮件发送?

捕获 HTML 格式的日志并通过电子邮件发送?

我创建了一个脚本来关闭 Oracle 数据库,但在数据库关闭成功完成时无法发送关闭的输出。我只收到回显部分的电子邮件,但没有收到关闭的实际部分。我想捕获 shutdown 的输出并将其发送mailx到我的emailid.

另请让我知道如何以 HTML 格式捕获此日志并通过 发送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

笔记:我的 Bash 版本:GNU bash,版本 4.1.2(1)-release (x86_64-redhat-linux-gnu)。

答案1

我通常会像这样做你想做的事:

#!/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]

上面创建了一个子 shell,它将捕获其中命令的所有输出。然后我们将所有这些输出mailx直接通过管道传输。

笔记:EOF使用此处文档时,请特别注意标记周围的任何额外间距。末尾错误的额外空格EOF可能会导致它无法工作。

参考

相关内容