#!/bin/ksh # ========================================================================= # # dbup.ksh # # Copyright (C)2000 Dejan Ilic - Oracle Consultant # # Downloaded from http://www.oriolecorp.com # # This script for Oracle database administration is free software; you # can redistribute it and/or modify it under the terms of the GNU General # Public License as published by the Free Software Foundation; either # version 2 of the License, or any later version. # # This script is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # ========================================================================= # # @(#) $Id: dbup,v 1.0 dd/mm/yy hh:mi:ss $ # @(#) $Type: Korn shell script $ # @(#) $Summary: Script for obtaining status of Oracle databases on machine $ # @(#) $Support: OSF1 $ # @(#) $Owner: oracle $ # @(#) $Copyright: Dejan Ilic $ # _ubeg_ # dbup(l) # # NAME # # dbup : status of databases on the server # # SYNOPSIS # # dbup # # DESCRIPTION # This is script for obtaining status of Oracle databases on machine. # It lists all the databases in the oratab file, plus those 'up' databases # which are unrecorded. # # EXAMPLE # # $ dbup # custodev (7.3.4) running # custopat (7.3.4) running # omsddr (7.3.4) running # omsdev (7.3.4) running # omspat (7.3.4) running # omspts (7.3.4) running # # AUTHOR # # Dejan Ilic - Oriole Consulting # # RELATED INFORMATION # # Commands: ksh(1) # # Documents: The Korn shell, Programming in Korn shell - David G. Korn # # _uend_ # # #================================================================= # # # main() # Verify that the environnement and associated files are in place # Also servers to show which files are used by the program # #================================================================= # typeset -i MEMBERSHIP typeset -i NOT_MEMBER=1 typeset -i IS_MEMBER=0 typeset -i cnt # # Function provides info on membership of one value in set of values # presented as an array. Member is first argument and must be supplied. Array # is represented by all other arguments. # Restriction: array element cannot contain white space characters since they # are already used to distinguish arguments in function call. # function in_set { __member=$1 __element=$__member while [[ ">${__element}<" != "><" ]] do shift 1 __element=$1 if [[ ">${__member}<" = ">${__element}<" ]] then return ${IS_MEMBER} fi done return ${NOT_MEMBER} } # # List of running databases # LPS=$(ps -eaf | grep ora_pmon_ | grep -v grep | grep -v print | awk -F"ora_pmon_" '{print $2}' | sort) # # Define full name of oratab file # ORATAB=/etc/oratab # # List of database SIDs from /etc/oratab # LOTSID=$(cat $ORATAB | grep -v "^#" | grep -v "^\*" | grep -v "^NFI" | sort | awk -F":" '{print $1}') # # List of database home subdirectories which, by convention, represents # version of Oracle RDBMS # LOTVER=$(cat $ORATAB | grep -v "^#" | grep -v "^\*" | sort | awk -F":" '{print $2}' | awk -F"/" '{print $(split($0,ARRAY))}') # # Repack values in array, so we can access them directly in the loop # set -A aLOTSID $LOTSID set -A aLOTVER $LOTVER # # Check which databases are running and which are down # cnt=0 for CDB in $LOTSID do if $(in_set $CDB $LPS) then printf "%10s (%4s) running\n" $CDB ${aLOTVER[$cnt]} else printf "%10s (%4s) down\n" $CDB ${aLOTVER[$cnt]} fi cnt=$((cnt + 1)) done # # Check if there are databases which are running and are not listed in $ORATAB # for RDB in $LPS do if ! $(in_set $RDB $LOTSID) then UNKNOWN_STATUS="(-??-)" printf "%10s (%4s) running\n" $RDB ${UNKNOWN_STATUS} fi done