自動監控Oracle 表空間資訊併傳送郵件指令碼
伺服器越來越多了,日常管理起來也越來越麻煩,也沒找到特別稱心如意的工具,如何自動的監控Oracle 告警日誌和表空間資訊呢?加入一臺伺服器有多個例項又如何監控呢?自己動手寫了一個小shell,貼出來以備後續更新!若有更好的可以不防共享出來哈
#!/bin/ksh
# script name is check_tablespace.sh
# created date: 2015-01-05
# guijian
################################### check information about oracle tablespace ####################################
if [ -d "$HOME/.check_tbs" ];then
echo "dir:$HOME/.check_tbs exists"
else
mkdir $HOME/.check_tbs
echo "dir:$HOME/.check_tbs created!"
fi
host_name=`hostname`
host_ip=`grep Crsz6scsdb02 /etc/hosts | grep -v '127.0.1.1' | grep -v localhost`
mail_list="guijian5@crc.com.hk"
oper_version=`uname -a | awk '{print $1}'`
if [ $oper_version = "Linux" ];then
ora_sid=`ps -ef | grep ora_pmon | grep -v grep |awk '{print $8}'|cut -d '_' -f3 | xargs`
sh $HOME/.bash_profile
else
ora_sid=`ps -ef | grep ora_pmon | grep -v grep |awk '{print $9}'|cut -d '_' -f3 | xargs`
sh $HOME/.profile
fi
echo "ora_sid:$ora_sid"
cat "######################### check information about oracle tablespace ##########################" > $HOME/.check_tbs/tbs.log
for i in $ora_sid
do
export ORACLE_SID=$i
echo $ORACLE_SID
alert_logfile=`find $ORACLE_BASE/ -name alert_$ORACLE_SID.log`
cd $logdir
number1=`cat $HOME/.check_tbs/tmp_alert_number`
sed -n "$number1,\$p" $alert_logfile > $HOME/.check_tbs/tmp_alert.log
wc -l $alert_logfile | awk '{print $1}' > $HOME/.check_tbs/tmp_alert_number
cat $HOME/.check_tbs/tmp_alert.log | grep -E 'ORA-|RMAN-' > $HOME/.check_tbs/alertlog_check.log
sqlplus -S /nolog<>$HOME/.check_tbs/tbs.log
conn / as sysdba
set line 140 pagesize 9999
col tablespace_name for a30
select instance_name,status from gv\$instance;
select T.tablespace_name,T.TOTAL_SPACE_MB,(T.TOTAL_SPACE_MB-F.FREE_SPACE_MB) "USED_SPACE_MB",F.FREE_SPACE_MB,(100-ROUND((T.TOTAL_SPACE_MB-F.FREE_SPACE_MB)/T.TOTAL_SPACE_MB*100,2)) "FREE_RATE %",ROUND((T.TOTAL_SPACE_MB-F.FREE_SPACE_MB)/T.TOTAL_SPACE_MB*100,2) "USED_RATE %" FROM (SELECT TABLESPACE_NAME,SUM(BYTES/1024/1024) "TOTAL_SPACE_MB" FROM DBA_DATA_FILES GROUP BY TABLESPACE_NAME) T,(SELECT TABLESPACE_NAME,ROUND(SUM(BYTES/1024/1024),2) "FREE_SPACE_MB" FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F WHERE T.TABLESPACE_NAME = F.TABLESPACE_NAME ORDER BY 6;
EOF
done
sed '/^$/d' $HOME/.check_tbs/tbs.log > $HOME/.check_tbs/tablespace.log
echo "#################################### alert log check #########################################" >> $HOME/.check_tbs/tablespace.log
cat $HOME/.check_tbs/alertlog_check.log >> $HOME/.check_tbs/tablespace.log
cat $HOME/.check_tbs/tablespace.log |mail -s "INSTANCE_NAME : $ora_sid HOST NAME AND IP ADDRESS : $host_ip" $mail_list
轉載請註明出處
#!/bin/ksh
# script name is check_tablespace.sh
# created date: 2015-01-05
# guijian
################################### check information about oracle tablespace ####################################
if [ -d "$HOME/.check_tbs" ];then
echo "dir:$HOME/.check_tbs exists"
else
mkdir $HOME/.check_tbs
echo "dir:$HOME/.check_tbs created!"
fi
host_name=`hostname`
host_ip=`grep Crsz6scsdb02 /etc/hosts | grep -v '127.0.1.1' | grep -v localhost`
mail_list="guijian5@crc.com.hk"
oper_version=`uname -a | awk '{print $1}'`
if [ $oper_version = "Linux" ];then
ora_sid=`ps -ef | grep ora_pmon | grep -v grep |awk '{print $8}'|cut -d '_' -f3 | xargs`
sh $HOME/.bash_profile
else
ora_sid=`ps -ef | grep ora_pmon | grep -v grep |awk '{print $9}'|cut -d '_' -f3 | xargs`
sh $HOME/.profile
fi
echo "ora_sid:$ora_sid"
cat "######################### check information about oracle tablespace ##########################" > $HOME/.check_tbs/tbs.log
for i in $ora_sid
do
export ORACLE_SID=$i
echo $ORACLE_SID
alert_logfile=`find $ORACLE_BASE/ -name alert_$ORACLE_SID.log`
cd $logdir
number1=`cat $HOME/.check_tbs/tmp_alert_number`
sed -n "$number1,\$p" $alert_logfile > $HOME/.check_tbs/tmp_alert.log
wc -l $alert_logfile | awk '{print $1}' > $HOME/.check_tbs/tmp_alert_number
cat $HOME/.check_tbs/tmp_alert.log | grep -E 'ORA-|RMAN-' > $HOME/.check_tbs/alertlog_check.log
sqlplus -S /nolog<
conn / as sysdba
set line 140 pagesize 9999
col tablespace_name for a30
select instance_name,status from gv\$instance;
select T.tablespace_name,T.TOTAL_SPACE_MB,(T.TOTAL_SPACE_MB-F.FREE_SPACE_MB) "USED_SPACE_MB",F.FREE_SPACE_MB,(100-ROUND((T.TOTAL_SPACE_MB-F.FREE_SPACE_MB)/T.TOTAL_SPACE_MB*100,2)) "FREE_RATE %",ROUND((T.TOTAL_SPACE_MB-F.FREE_SPACE_MB)/T.TOTAL_SPACE_MB*100,2) "USED_RATE %" FROM (SELECT TABLESPACE_NAME,SUM(BYTES/1024/1024) "TOTAL_SPACE_MB" FROM DBA_DATA_FILES GROUP BY TABLESPACE_NAME) T,(SELECT TABLESPACE_NAME,ROUND(SUM(BYTES/1024/1024),2) "FREE_SPACE_MB" FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F WHERE T.TABLESPACE_NAME = F.TABLESPACE_NAME ORDER BY 6;
EOF
done
sed '/^$/d' $HOME/.check_tbs/tbs.log > $HOME/.check_tbs/tablespace.log
echo "#################################### alert log check #########################################" >> $HOME/.check_tbs/tablespace.log
cat $HOME/.check_tbs/alertlog_check.log >> $HOME/.check_tbs/tablespace.log
cat $HOME/.check_tbs/tablespace.log |mail -s "INSTANCE_NAME : $ora_sid HOST NAME AND IP ADDRESS : $host_ip" $mail_list
轉載請註明出處
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28612416/viewspace-1392423/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 監控oracle表空間指令碼Oracle指令碼
- python實現自動監控網站併傳送郵件告警薦Python網站
- 用 Linux Shell 指令碼來監控磁碟使用情況併傳送郵件Linux指令碼
- oracle空間使用監控指令碼Oracle指令碼
- SAP BW 郵件傳送監控策略
- Python監控程序資源佔用併傳送郵件Python
- Linux發郵件磁碟空間監控Linux
- 監控硬碟空間指令碼硬碟指令碼
- Python3實現自動傳送MySql查詢併傳送郵件PythonMySql
- Oracle郵件傳送Oracle
- Oracle 自動化運維-Python表空間郵件預警Oracle運維Python
- Springboot 自動傳送郵件Spring Boot
- oracle表空間增加監控Oracle
- rman備份指令碼 傳送郵件通知指令碼
- 【Grafana】告警配置併傳送郵件Grafana
- Linux配置msmtp+mutt傳送郵件(可放在指令碼中定時傳送郵件)Linux指令碼
- Shell指令碼中傳送html郵件的方法指令碼HTML
- 【主機】傳送郵件指令碼的改進指令碼
- linux自動重起服務,併傳送郵件通知結果Linux
- linux下設定郵件自動傳送Linux
- 案例二十每分鐘監控錯誤日誌併傳送郵件給相關人員
- 郵件傳送庫原始碼原始碼
- 郵件傳送
- 傳送郵件
- 用oracle傳送電子郵件Oracle
- oracle 傳送郵件 實現方法Oracle
- 成功透過ORACLE傳送郵件Oracle
- 用Oracle傳送郵件procedure (zt)Oracle
- oracle監控表空間,JOB,rman備份Oracle
- 谷歌郵箱,配置傳送郵件密碼谷歌密碼
- oracle表空間傳輸的限制條件Oracle
- laravel 傳送郵件修改密碼Laravel密碼
- SpringBoot整合Mail傳送郵件&傳送模板郵件Spring BootAI
- 表空間郵件預警(luckyfriends)
- 移動表空間的指令碼指令碼
- ASP.NET自動傳送郵件功能的實現ASP.NET
- 自動生成addm報告並以郵件傳送
- 自動生成AWR報告並以郵件附件傳送