Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Need Script to check if database is up or down
In article <8dfo63$t7n$1_at_news.duke.edu> "John Jones" <john.jones_at_duke.edu> writes:
>Need immediate help from Unix System Guru's. I need a script that checks if
>the database is up or down. I DON'T need a script that checks for the
>existance of background processes.
>
>Here is my problem. I rebuild a reporting database nightly, I copy over the
>datafiles, do a startup nomount (which starts the background processes),
>then recreate the control file and start the database. Well if something
>goes wrong on the control file or starting the database, the database will
>not open, but the background processes are there. I tried writing a script
>that uses SQL*Plus to connect, but if the database is not there my script
>stops and prompts for another database connection, it will prompt three (3)
>times.
Use svrmgrl. You can query as long as you're in the mount state. I found that "*" wildcard it returns when not mounted to be a pain in the butt.
Here's one way, it's ugly (but hey! It's UNIX!):
ORACLE_SID=YourSID
ORACLE_HOME=YourHOME
PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID ORACLE_HOME PATH
status=`svrmgrl <<\EOD
connect / as sysdba
select status from v$instance ;
EOD
`
echo $status | \
awk '/ORA-01034/ { printf "Database is CLOSED \n"}
/OPEN/ { printf "Database is OPEN \n" } '
Jim G.
BBN Technologies
Cambridge, MA
>Need help, please respond to john.jones_at_duke.edu if you have a solution.
>
>--
>John Jones
>Senior Oracle DBA
>Duke University OIT
>john.jones_at_duke.edu
>
>
Received on Mon Apr 17 2000 - 00:00:00 CDT