Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Need oracle Script
Hi
There were quite a few solutions (scripts) posted to the list (and discussed) in the past. I am not sure if there is still the archive, but if there is one it might be a good idea to have a look there.
Here is a ksh example (it may be is not as elegant and simple as some others but does the job)
#!/bin/ksh
#
# This script checks for the status
# Created: Alex Afanassiev 05/02/199
# Last updated: 31/o8/1999
#
# WARNING: This script has been tested only v7.3.4.3 and v8i1.5
# It relies on x$ tables structure and output that could differ
# in Oracle releases
#
#JOBNAME="$0"
#JOBNAME_SHORT=`basename $JOBNAME`
ORATAB=/var/opt/oracle/oratab
if [ ! -s $ORATAB ]; then
echo "$ORATAB file does not exist. Searching all file systems..." ORATAB=`find / -name oratab 2>/dev/null | head -1` if [ "$ORATAB" = "" ]; then
echo "Cannot find oratab file. Aborting..." exit
echo
echo "Available ORACLE SIDS:" ${SIDLIST}
ORA_PROCESSES=5
for SID in `echo $SIDLIST`; do
PIDCNT=`ps -fu oracle |grep ora_ | grep $SID | wc -l`
if [ $PIDCNT -eq 0 ]; then
echo echo "$SID is down" else if [ $PIDCNT -ge $ORA_PROCESSES ]; then ORACLE_SID=$SID; export ORACLE_SID ORACLE_HOME=`cat ${ORATAB} | awk -F: '/^[^#]/' | grep $ORACLE_SID |cut -d ":" -f2` export ORACLE_HOME # get version $ORACLE_HOME/bin/svrmgrl << EOF > $OUT connect internal SELECT '***'||BANNER vers FROM x\$version WHERE indx = (SELECT min(indx) FROM x\$version); EOF if [ `cat $OUT | grep -c ORA-01034` -gt 0 ]; then STATUS="${ORACLE_SID} is started, not available; startup or shutdown process might be in progress" VERSION="" else VERSION=`cat $OUT | grep '\*\*\*' | cut -d "*" -f4` VERNO=`echo $VERSION | awk '{print $1}' |cut -c7` # init flags if [ $VERNO -lt 8 ]; then # DIFLG - Flag: 0 - archive log mode off; # 1 - archive log mode on # 5191 - mounted as standby # DIIRS - Incomplete recovery status # DINOT, DIOTH, DIOTT - ??? not sure which one is the open flag # guessing each of them should be set to 1 # $ORACLE_HOME/bin/svrmgrl << EOF > $OUT connect internal SELECT '***'||DIDBN||' database '|| DECODE(DIFLG, 0, 'is in NOARCHIVELOG mode'|| DECODE(DINOT+DIOTH+DIOTT, 3, ', OPEN', ', MOUNTED, NOT OPEN'), 1, 'is in ARCHIVELOG mode'|| DECODE(DINOT+DIOTH+DIOTT, 3, ', OPEN', ', MOUNTED, NOT OPEN'), 5191, 'mounted as a standby database', 'has unknown status '||DIFLG) ||DECODE(DIIRS,0,NULL, CHR(10)||CHR(13)||'***'|| ' Incomplete Recovery Status: ' ||DIIRS) status from x\$kccdi; EOF else $ORACLE_HOME/bin/svrmgrl << EOF > $OUT connect / as sysdba select '***'||name||' is in '|| log_mode|| ' mode'|| DECODE(open_mode, 'MOUNTED', ', MOUNTED, NOT OPEN', ', open as '|| open_mode) status from v\$database; EOF fi if [ `cat $OUT | grep -c 'ORA-01507: database not mounted'` -ne 0 ]; then STATUS="$ORACLE_SID instance started, database not mounted" else STATUS=`cat $OUT | grep '\*\*\*' | cut -d "*" -f4` fi fi echo echo "$VERSION" echo "ORACLE_HOME: $ORACLE_HOME" echo "$STATUS" else echo "ATTENTION!" echo "Less then $ORA_PROCESSES found for $SID" echo "some processes seems to be active" fi
echo "$PIDCNT listener(s) is active"
else
echo "No listener is active"
fi
if [ -s $OUT ]; then
rm $OUT
fi
# restore oracle vars
ORACLE_SID=$CUR_SID; export ORACLE_SID
ORACLE_HOME=$CUR_HOME; export ORACLE_HOME
echo
exit
With regards
Alex Afanassiev
Oracle DBA, TOC Operations Support/IDO
Tel: (03) 8 661 20 61 Fax: (03) 9 650 36 74 > -----Original Message----- > From: puja rahul [SMTP:puja-r_at_mailcity.com] > Sent: Saturday, June 17, 2000 11:56 AM > To: Multiple recipients of list ORACLE-L > Subject: Re: Need oracle Script > > Hi, > > I'm aware of the dbstart and dbshut scripts but I was wondering if there > is any script within oracle to see if all the databases mentioned in the > /etc/oratab file are up and running - and if for some reason the database > is not up - bring it up and online. > Instead for wrting a script taking the output of ps -ef to check ,which > will be little complicated I was trying to figure out if someone has a > script in place doing the > same job. > > I would highly appreciate the help. > > THanks in advance. > > cheers. > -- > > On Fri, 16 Jun 2000 05:39:47 > Chuck Hamilton wrote: > > > >You already have it. Check out $ORACLE_HOME/bin/dbstart. > > > > > >puja rahul > >wrote: > > > >Hi , > > > >I'm a unix admin and not at all a DBA.So I need some help in ORACLE. > >I have 12 instances of ORACLE running on my production box -\ > >( DIGITAL UNIX 4.0D is the OS on the box ) > >For some reasons at times after the night backup few data bases are not > coming up- > >I want to have a script that can run every morning after the backup is > complete to check the status of all the databases and if Any of the them > is not running do a clean startup of the databases which were not running > and send a mail saying that all datbases are up and running. > > > >Thanks a lot all of you in advance. > > > >Cheers > > > > > > > >Send FREE Greetings for Father's Day--or any day! > >Click here: http://www.whowhere.lycos.com/redirects/fathers_day.rdct > >-- > >Author: puja rahul > >INET: puja-r_at_mailcity.com > > > >Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 > >San Diego, California -- Public Internet access / Mailing Lists > >-------------------------------------------------------------------- > >To REMOVE yourself from this mailing list, send an E-Mail message > >to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in > >the message BODY, include a line containing: UNSUB ORACLE-L > >(or the name of mailing list you want to be removed from). You may > >also send the HELP command for other information (like subscribing). > > > > > > > > > >--------------------------------- > >Do You Yahoo!? > >Send instant messages with Yahoo! Messenger. > > > Send FREE Greetings for Father's Day--or any day! > Click here: http://www.whowhere.lycos.com/redirects/fathers_day.rdct > -- > Author: puja rahul > INET: puja-r_at_mailcity.com > > Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 > San Diego, California -- Public Internet access / Mailing Lists > --------------------------------------------------------------------> To REMOVE yourself from this mailing list, send an E-Mail message > to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in Received on Sun Jun 18 2000 - 20:02:35 CDT