Shell 检查Oracle 数据库状态

隐身守侯 提交于 2020-01-18 22:20:46

利用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=/TEMP/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 open_mode from v\$database;" >> $sql_script
echo "exit"                                           >> $sql_script

su - oradu8 -c "sqlplus -s /NOLOG @$sql_script" >$sql_script_out 2>/dev/null 0</dev/null
status=$( grep 'STATUS:' $sql_script_out| awk '{printf("%s %s\n",$2,$3)}'  )
echo ${status}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!