我正在尝试编写一个 shell 脚本来监视 Oracle 中的 ASM 实例并向邮件列表中的相应人员发送邮件。我写了以下脚本。
#/bin/sh
#set -x
USER=xxx
PASS=yyy
CC_OFFSHORE="[email protected] , [email protected] , [email protected]"
CC_TEAM="$CC_OFFSHORE , [email protected]"
. /home/oracle/.TESTenv #(NOT MANDATORY. DEPENDS ON YOUR ENVIRONMENT)
sqlplus -s $USER/$PASS << EOF
spool /home/oracle/SABARISH/RETVAL.log
set linesize 140
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
col group_number format 999
col diskgroup format a20
col total_mb format 999,999,999
col free_mb format 999,999,999
col tot_used format 999,999,999
col pct_used format 999
col pct_free format 999
select group_number,
name diskgroup,
total_mb,
free_mb,
total_mb-free_mb tot_used,
pct_used,
pct_free
from (select group_number,name,total_mb,free_mb,
round(((total_mb-nvl(free_mb,0))/decode(total_mb,0,1,total_mb))*100) pct_used,
round((free_mb/total_mb)*100) pct_free
from v\$asm_diskgroup
where total_mb >0
order by pct_free
)
/
spool off;
EOF
while read -r values
do
USED_PCT=$(echo $values | awk '{print $6}')
DISKGROUP_NAME=$(echo $values | awk '{print $2}')
WARNING_LIMIT=60
CRITICAL_LIMIT=70
if [ ${USED_PCT} -ge ${WARNING_LIMIT} ] && [ ${USED_PCT} -lt ${CRITICAL_LIMIT} ]
then
echo "WARNING ALERT. $DISKGROUP_NAME disk has used $USED_PCT%" | mailx -s "(WARNING ALERT $USED_PCT% used)" $CXC_OFFSHORE
elif [ ${USED_PCT} -ge ${CRITICAL_LIMIT} ]
then
echo "CRITICAL ALERT.$DISKGROUP_NAME disk has used $USED_PCT%" | mailx -s "(CRITICAL ALERT $USED_PCT% used)" $CXC_TEAM
fi
done < /home/oracle/SABARISH/RETVAL.log
上面的脚本运行完美。
我需要做的就是向脚本添加更多细节。在执行ASM实例查询之前,我们需要检查DB是否已启动并正在运行。
并检查 Oracle 中特定用户的密码是否已过期或处于活动状态。
然后运行ASM查询。如果上述两个约束均失败,则不应执行 ASM 实例查询。它应该退出。
我该如何实现它?