导航

linux_oracle_healthcheck.sh

Posted on 2016-10-11 11:33  datalife  阅读(739)  评论(0编辑  收藏  举报

#!/bin/bash
##########################################################################################
#     Script: LINUX_ORACLE.bash
##########################################################################################
#
# ORACLE HEALTH CHECK
##########################################################################################
DATE=$(date +%Y%m%d)
HOSTNAME=$(hostname)
HCDIR=/oracle/xunjian
HCFILE=${HCDIR}/orachk_${DATE}_${HOSTNAME}.log
#export ORACLE_SID=orcl1
#export ORACLE_BASE=/oracle/oracle
#export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
#export PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/oracle/bin:/u01/11.2.0/grid/bin:$ORACLE_HOME/bin:$ORACLE_HOME/dcm/bin:$ORACLE_HOME/webcache/bin:$ORACLE_HOME/opmn/bin
#export LD_LIBRARY_PATH=$ORACLE_HOME/lib
exec > $HCFILE
##############OS AND CLUSTER CHECK###########################################################
date
echo '######################################VMSTAT 2 10###########################################'
vmstat -S M 2 10
echo '######################################MEM USAGE#############################################'
free -m
echo '######################################FS STATUS#############################################'
df -h
echo '######################################CLUSTER STATUS########################################'
su - grid -c "crs_stat -t"
echo '######################################CRS STATUS############################################'
su - grid -c "crsctl check crs"
echo '######################################VOTEDISK STATUS#######################################'
su - grid -c "crsctl query css votedisk"
echo '######################################OCR STATUS############################################'
su - grid -c "ocrcheck"
echo '######################################OCR BACKUP############################################'
su - grid -c "ocrconfig -showbackup"
echo '######################################LSNR STATUS###########################################'
su - grid -c "lsnrctl status"
####################DB CHECK###########################################################
su - oracle -c "sqlplus -S / as sysdba" <<EOF
set pagesize 1000;
set linesize 200;
prompt ######################################DB NAME###############################################
select name from v\$database;
prompt ######################################INSTANCE STATUS######################################
select instance_name,status from gv\$instance;
prompt ######################################ARCHIVELOG MOD#######################################
archive log list;
prompt ######################################DB SIZE##############################################
select sum(bytes)/1024/1024/1024 DBSIZE_GB from dba_segments;
prompt ######################################STORAGE USEGE##############################################
col NAME for a20
set lin 150
select NAME,TOTAL_MB,FREE_MB,STATE from v\$asm_diskgroup;
prompt ######################################USERS################################################
col username format a25
col account_status format a18
col default_tablespace format a20
col temporary_tablespace format a20
select username,account_status,default_tablespace,temporary_tablespace from dba_users;
prompt ######################################CONTROLFILE###########################################
col name format a65;
select name,status from v\$controlfile;
prompt ######################################REDO LOG##############################################
col member format a60;
select f.member "member",  f.group# "group", l.bytes/1024/1024 "size",  l.status from v\$logfile f, v\$log l where f.group#=l.group#  order by f.group#,f.member;
prompt ######################################TABLESPACE############################################
set line 200 pagesize 9999
col tablespace_name for a20
select b.tablespace_name,round(sum(b.bytes)/1024/1024,0) sum_MB,
          round(sum(b.bytes)/1024/1024,0)-round(sum(nvl(a.bytes,0))/1024/1024,0) use_MB,
          round(sum(nvl(a.bytes,0))/1024/1024,0) free_MB,
          round((sum(b.bytes)-sum(nvl(a.bytes,0)))/sum(b.bytes),4)*100 use_precent
   from (select tablespace_name,file_id,sum(bytes) bytes from dba_free_space group by tablespace_name,file_id) a,
         dba_data_files b
   where a.file_id(+)=b.file_id and a.tablespace_name(+)=b.tablespace_name
   group by b.tablespace_name
   union all
   select b.tablespace_name,round(b.bytes/1024/1024,0) sum_MB,
          round(nvl(a.bytes,0)/1024/1024,0) use_MB,
          round(b.bytes/1024/1024,0)-round(nvl(a.bytes,0)/1024/1024,0) free_MB,
          round(nvl(a.bytes,0)/b.bytes,4)*100 use_precent
   from (select tablespace_name,sum(nvl(bytes_used,0)) bytes from gv\$temp_extent_pool group by tablespace_name) a,
        (select tablespace_name,sum(bytes) bytes from dba_temp_files group by tablespace_name)b
   where a.tablespace_name(+)=b.tablespace_name
   order by use_precent desc;
prompt ######################################DATA-TEMP FILE##############################################
col TABLESPACE_NAME for a15
col file_name for a50
set linesize 150
select TABLESPACE_NAME,FILE_NAME,FILE_ID,BYTES/1024/1024 mb,ONLINE_STATUS from dba_data_files
union all
select TABLESPACE_NAME,FILE_NAME,FILE_ID,BYTES/1024/1024 mb,STATUS from dba_temp_files
order by 1;
prompt ######################################INVALID OBJECTS#######################################
select count(*) from dba_objects where status = 'INVALID';
prompt ######################################UNUSE INDEX###########################################
select count(*) from dba_indexes  where status='UNUSABLE';
exit;
EOF
echo 'BACKGROUD ALERT'
echo '######################################BACKGROUD ALERT#########################################'
tail -500 /oracle/oracle/diag/rdbms/orcldb/orcldb1/trace/alert_orcldb1.log
echo '######################################END#####################################################'

########################FTP TO LOCAL###########################
HOST_IP=192.168.1.18
USRNM="ftp"
PWD="password"
LOCAL_DIR=/oracle/xunjian
REMOTE_DIR=/dbcheck/test

ftp -inv $HOST_IP<<!
user ${USRNM} ${PWD}
bin
prompt
lcd ${LOCAL_DIR}
cd ${REMOTE_DIR}
mput orachk_${STAMP}_${HOSTNAME}.log
bye
!
exit