通过Shell脚本得到数据库的基本信息

今天写了个Shell脚本,虽然实现的功能不多,但是个人感觉是一个好的开始,架子出来了,后面要补充的细节加进来就逐步完善了。
 这个脚本的运行效果如下:
OS    Version  is :[ RHEL_6.3 ]
 Oracle Version  is :[ 11.2.0.3.0]
 Oracle Instance is :[ dgtest ]
 dgtest
 ORACLE_HOME    is :[ /U01/app/oracle/product/11.2.0.2/db_1  ]
 Oracle  status  is :[ 11g PRIMARY ]
 Oracle SPFILE  is :[ ENABLED ]
 Oralce DGBroker is :[ DISABLED ]
 FORCE LOGGING  is :[ DISABLED ]
 HugePage Status is :[ DISABLED ]
这个脚本会对大部分的信息进行一个概览,我想在这些内容的基础上添加更多的经验所得。
 运行这个脚本,好与不好一目了然,当然现在的功能还是有距离,慢慢改进吧。
 值得说道的是“Oracle status”的地方,会判断主备库,区分了10g,11g的不同特点。
 当然后面的大篇幅脚本是关于HugePage的,这个地方想补充出建议的值来,所以暂且这样。

脚本内容如下:
. /home/oracle/.bash_profile
 # Get OS Version
 echo  'OS    Version  is :[' `cat /etc/issue|sed  -e 's/Red Hat Enterprise Linux Server release/RHEL/g' -e 's/Red Hat Enterprise Linux AS release/RHEL/g' -e 's/ /_/g' -e 's/_(Tikanga)//g' -e 's/_(Santiago)//g' -e 's/_release//g' -e 's/_(Final)//g' -e 's/Nahant_Update_//g'|head -1` ]

# Get Oracle Version
 echo 'Oracle Version  is :[ '`sqlplus -v|sed '/^$/d'|awk '{print $3}'`]

# Get Oracle Instance List
 echo 'Oracle Instance is :[ '`ps -ef|grep smon|grep -v grep|awk  '{gsub("ora_smon_","",$8)}{print $8}'|grep -v awk` ]

for tmp_db in `ps -ef|grep smon|grep -v grep|awk  '{gsub("ora_smon_","",$8)}{print $8}'|grep -v awk`
 do
 echo $tmp_db

#Get Oracle Home
 echo 'ORACLE_HOME    is :[' $ORACLE_HOME ' ]'

# Get database role
 su -l oracle <<EOS
 export ORACLE_SID=${tmp_db}

$ORACLE_HOME/bin/sqlplus -s / as sysdba <<EOF
  set pages 0
  set feedback off
  select 'Oracle  status  is :[ '||decode(substr(version,1,2),11,
  (select decode(database_role,'PHYSICAL STANDBY',(decode(open_mode,'READ ONLY WITH APPLY','11g ADG','11g DG NEED_CHECK')),'PRIMARY','11g PRIMARY') from v\\\$database),
  10,
  (select decode(database_role,'PHYSICAL STANDBY',(decode(open_mode,'MOUNTED','10g DG NORMAL','10g DG NEED_CHECK')),'PRIMARY','10g PRIMARY') from v\\\$database)
  )||' ]' DG_MODE
  from v\\\$instance;
  select decode(value,null,'Oralce SPFILE  is :[ DISABLED ]','Oracle SPFILE  is :[ ENABLED ]') from v\\\$parameter where;
  select decode(upper(value),'FALSE','Oralce DGBroker is :[ DISABLED ]','Oracle DGBroker is :[ ENABLED ]') from v\\\$parameter where;
  select decode(force_logging,'NO','FORCE LOGGING  is :[ DISABLED ]','FORCE LOGGING  is :[ ENABLED ]') from v\\\$database;
 EOF
 EOS
 done

# Check HugePage enabled
 # Check for the kernel version
 KERN=`uname -r | awk -F. '{ printf("%d.%d\n",$1,$2); }'`
 # Find out the HugePage size
 HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {'print $2'}`
 # Start from 1 pages to be on the safe side and guarantee 1 free HugePage
 NUM_PG=1
 # Cumulative number of pages required to handle the running shared memory segments
 for SEG_BYTES in `ipcs -m | awk {'print $5'} | grep "[0-9][0-9]*"`
 do
    MIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`
    if [ $MIN_PG -gt 0 ]; then
      NUM_PG=`echo "$NUM_PG+$MIN_PG+1" | bc -q`
    fi
 done
 case $KERN in
    '2.4') HUGETLB_POOL=`echo "$NUM_PG*$HPG_SZ/1024" | bc -q`;
          grep vm.hugetlb_pool /etc/sysctl.conf|awk  '{print $0==""?"HugePage Status :[ DISABLED ]":"HugePage Status is :[ ENABLED ]"}';;
    '2.6') grep vm.nr_hugepages /etc/sysctl.conf|xargs echo $1|awk  '{print $0==""?"HugePage Status is :[ DISABLED ]":"HugePage Status is :[ ENABLED ]"}';;
    *) echo "Unrecognized kernel version $KERN. Exiting." ;;
 esac

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/db35ae71fc396d806e81064c9c2ad54e.html