Shell磁碟空間和表空間告警程式

muxinqing發表於2015-06-19

把下面內容新增到資料夾裡面
/etc/mail.rc

set from=1423646477@139.com
set smtp=smtp.139.com
set smtp-auth=login
set smtp-auth-user=253645765878@139.com
set smtp-auth-password=2015
set ssl-verify=ignore

這下面指令碼
#!/bin/bash
#More than 80% the alarm
#Contents are saved to disk/home/oracle/disk.log
#Please don't delete log cover
#make script mxq
#find /home/oracle -mtime +5 -name "*sql.xls" -exec rm -f   {} \;
disk_free=$(df -P | grep /dev | awk '{print $5}' | cut -f 1 -d "%")
#disk_mail=$(df -h)




df -h > /home/oracle/disk.log
for  l in  $disk_free

do

if [ $l -gt 90 ]; then

echo "The remaining space is less than 80% the alarm"|mail -s 'Disk monitoring' 25463131131@qq.com < /home/oracle/disk.log

break 1

fi
done

oracle_use=$(su - oracle -c "sqlplus -silent / as sysdba" << m| awk '{print $1}' | cut -f 1 -d "%"
set pagesize 0 feedback off verify off heading off echo off numwidth 4
select to_char(round((t.full_space-nvl(f.free_space,0))/t.full_space*100))||'%' "使用率" from (select tablespace_name,round(sum(bytes)/(1024*1024),2) free_space from dba_free_space group by tablespace_name) f ,(select tablespace_name,round(sum(bytes)/(1024*1024),2) full_space from dba_data_files group by tablespace_name) t where f.tablespace_name=t.tablespace_name(+);
exit
m
)

su - oracle -c "sqlplus -silent / as sysdba" << m > /home/oracle/tablespace.log
set feedback off
select t.tablespace_name "tablespace_name",t.full_space "total M",(t.full_space-nvl(f.free_space,0)) "USE M",f.free_space "FREE M",to_char(round((t.full_space-nvl(f.free_space,0))/t.full_space*100,1),'fm999990.99999')||'%' "rate" from (select tablespace_name,round(sum(bytes)/(1024*1024),2) free_space from dba_free_space group by tablespace_name) f,(select tablespace_name,round(sum(bytes)/(1024*1024),2) full_space from dba_data_files group by tablespace_name) t where f.tablespace_name=t.tablespace_name(+);
exit
m



for  oracle_all in  $oracle_use

do

if [ $oracle_all -gt 80 ]; then

echo "The remaining space is less than 80% the alarm"|mail -s 'Disk monitoring' 285313132221@qq.com < /home/oracle/tablespace.log

break 1

fi
done

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29065182/viewspace-1705169/,如需轉載,請註明出處,否則將追究法律責任。

相關文章