[ORACLE][SHELL] shell 检查Oracle 数据库状态

利用shell 来检查Oracle数据库状态

运行结果返回Oracle 数据库的状态

#! /usr/bin/ksh
#+++++++++++++++++++++++++++++++++++++++++++++
# Get ORACLE_SID DB Satus of 
#
# Param 1 : ORACLE_SID 
#+++++++++++++++++++++++++++++++++++++++++++++
if [ $# -ne 1 ]
then
  echo "Syntax : get_db_status <oracle_sid>"
  exit 8
fi

sql_script=/tmp/get_db_status.$$.sql
sql_script_out=$sql_script.out


echo "connect / as sysdba"                            >  $sql_script
echo "            "                                   >> $sql_script
echo "            "                                   >> $sql_script
echo "set head off"                                   >> $sql_script
echo "set pagesize 0"                                 >> $sql_script
echo "set linesize 1000"                              >> $sql_script
echo "select 'STATUS ' || open_mode from v\$database;" >> $sql_script
echo "exit"                                           >> $sql_script

su - oracle -c "sqlplus -s /NOLOG @$sql_script" >$sql_script_out 2>/dev/null 0</dev/null


if [ -f $sql_script_out ]
then 
   status=$( grep 'STATUS' $sql_script_out| awk '{printf("%s %s\n",$2,$3)}'  )

   case $status in
     "READ WRITE") stat="OPEN" ;;
     "MOUNTED " | "READ ONLY") stat="MOUNT" ;;
     *) stat="NOTAVAILABLE" ;;
  esac
else
    stat="NOTAVAILABLE"
fi
rm -f $sql_script_out $sql_script
typeset -u $stat
echo "DATASE $1 IS :" ${stat}

result:

[root@d4cdb Autoscript]# ./getdbstatu.sh D4C
DATASE D4C IS : NOTAVAILABLE
[root@d4cdb Autoscript]# ./getdbstatu.sh D4C
DATASE D4C IS : NOTAVAILABLE
[root@d4cdb Autoscript]# ./getdbstatu.sh D4C
DATASE D4C IS : MOUNT

 

posted on 2020-01-18 21:27  InnoLeo  阅读(910)  评论(0编辑  收藏  举报