standby checking script 3则 V1 shell 脚本

---1

#!/bin/sh

export ORACLE_SID=hdb
export ORACLE_BASE=/db/hdbdg/app/product/database
export ORACLE_HOME=/db/hdbdg/app/product/database/11g
export LANG=en_US
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export PATH=$PATH:$ORACLE_HOME/bin:.

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
#备库
get_result=`sqlplus '/ as sysdba'<<EOF
spool off;
select 'stdcseq1=' || max(sequence#) from v\\$archived_log where thread#=1 and applied='YES' group by thread#;
quit;
EOF`
stdcseq1=`echo "$get_result"|grep stdcseq1|cut -d "=" -f2`
echo $stdcseq1

get_result=`sqlplus '/ as sysdba'<<EOF
spool off;
select 'stdcseq2=' || max(sequence#) from v\\$archived_log where thread#=2 and applied='YES' group by thread#;
quit;
EOF`
stdcseq2=`echo "$get_result"|grep stdcseq2|cut -d "=" -f2`
echo $stdcseq2

#主库
get_result=`sqlplus dbmonopr/dbmonoprhdb11@hdb<<EOF
spool off;
select 'seq1=' || max(sequence#) from v\\$archived_log where thread#=1 group by thread#;
quit;
EOF`
echo "$get_result"
seq1=`echo "$get_result"|grep seq1|cut -d "=" -f2`
echo $seq1

seqdiff1=`expr $seq1 - $stdcseq1`

echo 'seqdiff1='$seqdiff1

if [ $seqdiff1 -ge 10 ]
then
echo "CRITICAL - hdb database dataguard error large than 10."
exit 2
fi

if [ $seqdiff1 -ge 6 ]
then
echo "WARNING - hdb database dataguard error large than 6."
exit 1
fi

if [ $seqdiff1 -lt 6 ]
then
echo "OK - hdb database dataguard ok."
exit 0
fi

############2:

version=`sqlplus -v|awk '{print $3}'|awk -F '.' '{print $1}'`

process_status='select status from v$managed_standby where process!='"'ARCH' and process like '%MRP%';"
status=`sqlplus -S / as sysdba<<EOF
set heading off
set feedback off
$process_status
exit
EOF`
echo mrp_status=$status

synctime="select to_char(first_time,'""yyyy-mm-dd hh24:mi:ss'"') from v$log_history where recid in (select max(recid) from v$log_history b group by thread#);'
time=`sqlplus -S / as sysdba<<EOF
set heading off
set feedback off
$synctime
exit
EOF`
echo synctime=$time

system=`uname`
case $system in
AIX)
disk_usage=`df -g|egrep -i "archive|fra" |awk '{print $(NF-3)}'`
if [ -n "$disk_usage" ];
then
echo archivedisk_usage=$disk_usage
fi
;;
HP-UX)
disk_usage=`bdf |egrep -i "archive|fra" |awk '{print $(NF-1)}'`
if [ -n "$disk_usage" ];
then
echo archivedisk_usage=$disk_usage
fi
;;
Linux)
disk_usage=`df -h|egrep -i "archive|fra" |awk '{print $(NF-1)}'`
if [ -n "$disk_usage" ];
then
echo archivedisk_usage=$disk_usage
fi
;;
esac

if [ -z "$disk_usage" ];
then
recovery_dest='select value from v$system_parameter where name = '"'db_recovery_file_dest';"
dest=`sqlplus -S / as sysdba<<EOF
set heading off
set feedback off
$recovery_dest
exit
EOF`
dest=${dest#*+}

asmdisk_usage_sql='select round((1-(free_mb/total_mb))*100,2) from v$asm_diskgroup where name='"'$dest';"
asmdisk_usage=`sqlplus -S / as sysdba<<EOF
set heading off
set feedback off
$asmdisk_usage_sql
exit
EOF`
echo archivedisk_usage=${asmdisk_usage}%
fi

if [ $version -eq 10 ];
then
recovery_dest_usage='select PERCENT_SPACE_USED from v$flash_recovery_area_usage where FILE_TYPE like '"'%ARCHIVE%';"
fi

if [ $version -eq 11 ];
then
recovery_dest_usage='select PERCENT_SPACE_USED from v$flash_recovery_area_usage where FILE_TYPE = '"'ARCHIVED LOG';"
fi

usage=`sqlplus -S / as sysdba<<EOF
set heading off
set feedback off
$recovery_dest_usage
exit
EOF`
echo fra_usage=${usage}%

###########3

#!/bin/bash
#env
PATH=/usr/local/bin:/usr/bin:$PATH:.
source /home/oracle11g/.bash_profile

f_getparameter(){
if [ -z "$3" ]; then
return
fi
PARAMETER=$1
sqlplus -s /nolog <<EOF | awk -F= "/^a=/ {print \$2}"
##sqlplus -s /nolog <<EOF
set head off pagesize 0 feedback off linesize 200
whenever sqlerror exit 1
##conn / as sysdba
##conn ${LOGIN_ID}@${db_name}
conn $2@$3
select 'a='||value from v\$parameter where name = '$PARAMETER';
EOF
}

f_getvalues(){
if [ -z "$3" ]; then
return
fi
PARAMETER=$1
sqlplus -s /nolog <<EOF | awk -F= "/^a=/ {print \$2}"
##sqlplus -s /nolog <<EOF
set head off pagesize 0 feedback off linesize 200
whenever sqlerror exit 1
##conn / as sysdba
##conn ${LOGIN_ID}@${db_name}
conn $2@$3
select 'a='||round(max_utilization/limit_value*100) from v\$resource_limit where resource_name='$PARAMETER';
EOF
}

f_getlist(){
if [ -z "$1" ]; then
return
fi
PARAMETER=$1
# sqlplus -s /nolog <<EOF | awk -F= "/^a=/ {print \$2}"
sqlplus -s /nolog <<EOF
set head off pagesize 0 feedack off linesize 50
whenever sqlerror exit 1
conn $2@$3
select status from v\$managed_standby where process!='ARCH' and process like '%MRP%';
select to_char(first_time,'yyyy-mm-dd hh24:mi:ss') from v\$log_history where recid in (select max(recid) from v\$log_history b group by thread#);
select PERCENT_SPACE_USED from v\$flash_recovery_area_usage where FILE_TYPE like 'ARCHIVE%';
EOF
}

db_list_checking(){

db_list="ora11g_test sdbs"
#db_list="sdbs"
##remove rdbs because 210.187 can't telnet 58.8.95.3 port 1528,need network check more
for db_name in ${db_list}

do
LOGIN_ID=dbmgr/t1234DBA

echo "###########$db_name###"

#echo $list
f_getlist ANY $LOGIN_ID $db_name

done

}
main()
{
echo '----------------'`date`'------------------checing konw---------------------------'

db_list_checking

echo '----------------'`date`'------------------over---------------------------'

}

main

上一篇:Introduction To Monte Carlo Methods


下一篇:[转]浅谈Android五大布局(二)——RelativeLayout和TableLayout