HTML邮件发送Oracle表空间占用百分比

前段时间写了一个监控Oracle表空间百分比的shell脚本,功能是实现了,但是发送的报警邮件内容排版不是很好,今天偷巧稍微改动了下,排版还不错。不多说了,详情脚本:

#!/bin/bash
#
# Description: Check local Oracle database tablespace usage rate,
# It will send mail to admin when then usage rate more than 95%.
#
logfile='/tmp/tablespace_check.log'
tmpfile='/tmp/tablespace_check.txt'
num=0
                                                              
. ~oracle/.bash_profile
                                                              
echo "From: szmlserver95_66<oracle@szmlserver95_66.abc.com>
To: kavin_yang<[email protected]>
Content-type: text/html;charset=UTF-8
Subject: Tablespace Usage Rate more than 95%
<pre>" > $tmpfile
                                                              
sqlplus / as sysdba << kavinEOF
set feedback off;
spool  $tmpfile append;
select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "Used MB",b.bytes/1024/1024 "Free MB",round(((a.bytes-b.bytes)/a.bytes)*100,2) "Percent_used"
from
(select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,
(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
where a.tablespace_name=b.tablespace_name
order by ((a.bytes-b.bytes)/a.bytes) desc;
spool off;
set feedback on;
exit;
kavinEOF
                                                              
if [ $? -ne 0 ];then
   mail -s "Tablespace Usage Rate run fail-95.66" [email protected] < $logfile
   exit 1
fi
                                                              
p_zyk_qd=`awk '$1 ~ /ZYK_QD/ {print $5}' $tmpfile`
p_stat_data=`awk '$1 ~ /STAT_DATA/ {print $5}' $tmpfile`
p_all_mchn_vst=`awk '$1 ~ /ALL_MCHN_VST/ {print $5}' $tmpfile`
p_zy_mchn_vst=`awk '$1 ~ /ZY_MCHN_VST/ {print $5}' $tmpfile`
p_app_log=`awk '$1 ~ /APP_LOG/ {print $5}' $tmpfile`
   
for i in $p_zyk_qd $p_stat_data $p_all_mchn_vst $p_zy_mchn_vst $p_app_log                                                            
do
  if [ $(echo "$i >= 90" | bc ) = 1 ];then
     num=$((num+1))
  fi
done
                                                            
if [ $num -gt 0 ];then
   echo "</pre>" >> $tmpfile
   cat "$tmpfile" | sendmail -t
fi
rm -f $tmpfile
exit 0

示例图如下:

171554425.jpg


你可能感兴趣的:(oracle表空间,shell发送html邮件)