DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: unix script to check database open

Hybrid View

  1. #1
    Join Date
    Apr 2001
    Location
    London
    Posts
    725
    SCO Unixware 7
    Oracle 8.1.6

    Hi Friends...

    I need to write unix script which will check whether my database is open and and if not to mail me...

    Can anyone save me some time and supply me with one ???

    Thanks

    Suresh
    Once you have eliminated all of the impossible,
    whatever remains however improbable,
    must be true.

  2. #2
    Join Date
    Apr 2001
    Location
    London
    Posts
    725
    Alright Folks..

    Got one now....

    Modified dbstart
    Once you have eliminated all of the impossible,
    whatever remains however improbable,
    must be true.

  3. #3

    Hehe! Would you mail, pliiiz?
    liviu@e-go.ro
    ovidius over!

  4. #4
    Join Date
    Dec 2001
    Location
    Keene, NH
    Posts
    510
    I needed a script to tell me what the state of the instance/dB was so I wrote this one. The scripts exits with a 1, 2 or 3 depending on the state. To see if the instance is started, I check the O/S for smon...for mounted and OPEN I check v$instance (Oracle 9i).

    #!/bin/ksh
    LOG=/tmp/state.log
    echo "-------------------------------------------------------" | tee $LOG
    if [ ! $# -eq 1 ]
    then
    echo "Usage: state_instance.ksh takes one parameter (SID)." | tee -a $LOG
    echo "-----------------------------------------------" | tee -a $LOG
    exit
    fi

    sname=$1
    echo "state_instance.ksh : start of script : SID = $sname"
    ###############################
    ### Is the instance started ###
    ###############################
    string="ora_smon_"$sname
    ps -ef | grep $string
    cnt=`ps -ef | grep $string | wc -l`

    #the reason I check for 2 is becuae of the grep statement will be counted.
    if [ $cnt -eq 2 ]
    then
    echo "" | tee -a $LOG
    echo "state_instance.ksh: The instance is started...." | tee -a $LOG
    else
    echo "state_instance.ksh: The instance is NOT started...." | tee -a $LOG
    exit 0
    fi

    ###################################################
    ## The instance IS started, Now check for OPENED ##
    ###################################################
    $ORACLE_HOME/bin/sqlplus -s << END > /tmp/hold.txt
    connect / as sysdba
    set head off
    select 'STATUS:' || status from v\$instance;
    END

    grep "STATUS:" /tmp/hold.txt | awk -F":" '{print $2}' | tee -a $LOG
    status=`grep "STATUS:" /tmp/hold.txt | awk -F":" '{print $2}'`
    #echo "#"$status"#"

    echo "-------------------------------------------------------" | tee -a $LOG
    case $status in

    STARTED) exit 1
    ;;
    MOUNTED) exit 2
    ;;
    OPEN) exit 3
    ;;

  5. #5
    Join Date
    Nov 2000
    Location
    Birmingham, UK
    Posts
    360
    Just a thought:

    cnt=`ps -ef | grep $string | wc -l`

    #the reason I check for 2 is becuae of the grep statement will be counted.
    if [ $cnt -eq 2 ]


    You could use grep -v in order to not count the grep i.e.

    cnt=`ps -ef | grep $string | grep -v grep | wc -l`

    if [ $cnt -eq 1 ]

  6. #6
    Join Date
    Dec 2001
    Location
    Keene, NH
    Posts
    510
    Thanks fraze!!!

    One more note to Sureshy..please check that STATUS exists in v$instance prior to 9i

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width