#!/usr/bin/sh #--------------------------------------------------- # check system script # Author :libin # Date :2008-01-11 # Version :1.0 # Description: 查詢數據庫空間 # 當指定目錄的空間達到警戒值時, 向指定的號碼發送告警短信 # # #---------------------------------------------------
# 監控的目錄 [注, 多個目錄以豎線分割] DISK_SPACE='oracle|arch|var|opt|/$'
# 接收短信號碼 [注, 多個號碼以tab分隔] SVCNUM_LIST="号码1 号码2"
# 主機名 HOSTNAME="数据库主机"
# 臨界點 ERROR=90 WARNING=80 INFO=75 DEBUG=5
# 運行時選取的臨界點 #RUN_LEVEL=${DEBUG} RUN_LEVEL=${WARNING}
# 向接口表插數據, 發送短信 send_sm() { # 號碼 local vc_svcnum="$1"
# 短信信息 local vc_sminfo="$2"
# 鏈接數據庫, 發送短信 $ORACLE_HOME/bin/sqlplus aaa/bbb@ccc <<EOF_SEND_SM set linesize 300 set heading off insert into tab_xxx (....
svcnums,
sminfo, ....
)
values (..., '$vc_svcnum', ... '$vc_sminfo',
...); commit; exit EOF_SEND_SM }
# used 由百分比 換為 數值 for bdf_list in `bdf | grep -E $DISK_SPACE | awk '{printf("%s,%s,%s,%s,%d,%s\n",$1,$2,$3,$4,$5,$6)}'` do filesystem="`echo $bdf_list | awk '{FS=","} {print $1}'`" kbytes="`echo $bdf_list | awk '{FS=","} {print $2}'`" used="`echo $bdf_list | awk '{FS=","} {print $3}'`" avail="`echo $bdf_list | awk '{FS=","} {print $4}'`" used="`echo $bdf_list | awk '{FS=","} {print $5}'`" mounted_on="`echo $bdf_list | awk '{FS=","} {print $6}'`"
echo "目錄:"$mounted_on echo "使用的空間數:"$used"%"
if [ $used -ge ${RUN_LEVEL} ] then # 向列表中的號碼發送告警短信 for svcnum in $SVCNUM_LIST do # 短信內容 message="主機[${HOSTNAME}]空間告警. [WARNING]目錄: ${mounted_on} 空間使用率:${used}%"
send_sm "$svcnum" "${message}" 1>/dev/null 2>&1 #echo "[$svcnum]" "${message}"
sleep 1 done fi done
|