#!/usr/bin/ksh ################################################################################ # static variable ################################################################################ set -A arr_db set -A arr_home set -A arr_state ################################################################################ # dynamic varaible ################################################################################ ORATAB=/etc/oratab ORACLE_GROUP=dba ################################################################################ # Function error Msg ################################################################################ function err_msg { MSG="Invalid Selection..." } ################################################################################ # Show Menu Structur ################################################################################ function show_menu { clear index=0 echo "\n\tSelect an Instance:\n" for elements in ${arr_db[@]} do echo "\t ${index}. ${arr_db[${index}]}\t(${arr_state[${index}]})" index=$(( ${index} + 1 )) done echo "\n\t99. Exit\n" echo ${MSG} echo "Enter a Number" } ################################################################################ # Main Programm ################################################################################ #clear the screen clear if [ 0 -eq $(id | grep -c ${ORACLE_GROUP}) ] then echo Error: $(whoami) not member of the ${ORACLE_GROUP} group! exit 1; fi if [ ! $ORATAB ] ; then echo "Set ORATAB to dir where oratab file is located" exit 1; fi index=0 cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if [ "$ORACLE_SID" = '*' ] ; then # same as NULL SID - ignore this entry ORACLE_SID="" continue fi #Proceed only if last field is 'Y'. if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then if [[ $(echo $ORACLE_SID | cut -b 1) = '+' ]] then arr_db[${index}]="${ORACLE_SID}:(asmcmd)" arr_home[${index}]=$(echo $LINE | awk -F: '{print $2}' -) #Check for DB-Status if [[ $(ps -ef | grep -v grep | grep -c ocssd.bin) -eq 1 ]] then arr_state[${index}]=up else arr_state[${index}]=down fi index=$(( ${index} + 1 )) fi arr_db[${index}]=${ORACLE_SID} arr_home[${index}]=$(echo $LINE | awk -F: '{print $2}' -) #Check for DB-Status if [[ $(ps -ef | grep -v grep | grep -c _pmon_${ORACLE_SID}) -eq 1 ]] then arr_state[${index}]=up else arr_state[${index}]=down fi index=$(( ${index} + 1 )) fi ;; esac done while true do show_menu MSG="" read dummy if [ ${dummy} -eq 99 ] then export ORACLE_HOME=${arr_home[${dummy}]} export ORACLE_SID=${arr_db[${dummy}]} exit fi #check for nummeric user input if [[ $dummy = +([[:digit:]]) ]] then if [[ ${dummy} -lt ${#arr_db[@]} ]] then export ORACLE_SID=${arr_db[${dummy}]} clear if [[ $(echo $ORACLE_SID | grep -c asmcmd) -ge 1 ]] then export ORACLE_HOME=${arr_home[${dummy}]} export ORACLE_SID=$(echo ${ORACLE_SID} | awk -F: '{print $1}') asmcmd -p else export ORACLE_HOME=${arr_home[${dummy}]} export ORACLE_SID=${arr_db[${dummy}]} sqlplus / as sysdba fi else err_msg fi else err_msg fi done