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

Thread: shell script to check remote db is up ?

  1. #1
    Join Date
    Oct 2000
    Posts
    250

    shell script to check remote db is up ?

    Hi anyone has shell script to check the remote db is up or not ?
    If all the login username and password are unknown... will it be too difficult to put the check in script ?

    Your contribution is very much appreciated. Thank You.

  2. #2
    Join Date
    Jan 2001
    Posts
    2,828
    Hi

    Well the only realy way to check wheather the database is up or not would be to from a shell script taht can actually login into the databse and do somethin like seelect sysdate from dual;..other methods like checking for ps -ef |grep smon and might be useful..but what if the database is just mounted and not open..your pager would ring anyway :-)



    regards
    Hrishy

  3. #3
    Join Date
    May 2001
    Location
    London
    Posts
    149
    log in into that server then check weather any oracle background process is running or not

    U can check by using

    ps -aef | grep dbwr

  4. #4
    Join Date
    Jun 2000
    Location
    Madrid, Spain
    Posts
    7,447
    Code:
    #!/bin/ksh 
    
    #DIR_EJE=${HOME_EXP}/shell
    DIR_EJE=/home/oracle7/admin/control-m/ORADISPONIBLE
    #TNS_ADMIN=${DIR_EJE}
    TNS_ADMIN=/home/oracle7/admin/control-m/TNS_ADMIN
    OPCION=
    TECLA=
    ORACLE_HOME=/home/ttd/oracle/app/oracle/product/7.3.4
    
    uso()
    {
     echo ""
     printf "Elija una de las opciones posibles [1, 2, 3, 4]"
     echo ""
    }
    
    continua()
    {
     echo ""
     echo ""
     echo "Pulsa una tecla para continuar ...........\c"
     read TEC
    }
    
    menu()
    {
     clear
     echo ""
     echo ""
     echo ""
     echo ""
     echo ""
     echo ""
     printf "\t\t\tElija una opcion:\n"
     printf "\t\t\t=================\n"
     echo ""
     echo ""
     printf "\t\t\t1. Disponibilidad bases de datos produccion\n"
     echo ""
     printf "\t\t\t2. Disponibilidad comunicaciones\n"
     echo ""
     printf "\t\t\t3. Disponibilidad Oracle Comunicaciones\n"
     echo ""
     printf "\t\t\t4. Salir\n"
     echo ""
    }
    
    disponible()
    {
     echo ""
     echo "Fecha de ejecucion del script : `date`"
     echo ""
     
     printf "\t\tB Datos\t\tDominio\t\t\tEstado\n"
     printf "\t\t=======\t\t=======\t\t\t======\n"
     printf "\n"
     cat ${DIR_EJE}/bbdd.conf | grep -v "#" | while read dominio bbdd version
     do
            FICHERO_RESUL=${DIR_EJE}/dispon${bbdd}.txt
            [[ -f $FICHERO_RESUL ]] && rm -f $FICHERO_RESUL
            ${DIR_EJE}/oradisponible ${bbdd}_${dominio} > $FICHERO_RESUL
            estado=$?
            printf "\t\t"${bbdd}"\t\t"%11s"\t\t\c" ${dominio}
            if [ $estado -eq 0 ];then
                    msgestado=OK
            else    
                    if [ $estado -eq 1 ];then
                            msgestado=ERROR
                    else
                            msgestado=AVISO
                    fi
            fi
            printf $msgestado": "
            cat $FICHERO_RESUL
            [[ -f $FICHERO_RESUL ]] && rm -f $FICHERO_RESUL
     done
    
    }
    
    tnsping()
    {
     echo ""
     echo "Fecha de ejecucion del script : `date`"
     echo ""
    
     print "\t\tB Datos\t\tDominio\t\t\tEstado"
     print "\t\t=======\t\t=======\t\t\t======"
     print ""
     cat ${DIR_EJE}/bbdd.conf | grep -v "#" | while read dominio bbdd version
     do
            FICHERO_RESUL=${DIR_EJE}/dispon${bbdd}.txt
            [[ -f $FICHERO_RESUL ]] && rm -f $FICHERO_RESUL
            ${ORACLE_HOME}/bin/tnsping ${bbdd}_${dominio} > $FICHERO_RESUL
            estado=$?
            printf "\t\t"${bbdd}"\t\t"%11s"\t\t\c" ${dominio}
            if [ $estado -eq 0 ];then
                    msgestado=OK
            else
                    if [ $estado -eq 1 ];then
                            msgestado=ERROR
                    else
                            msgestado=AVISO
                    fi
            fi
            printf $msgestado": "
            tail -1 $FICHERO_RESUL
            [[ -f $FICHERO_RESUL ]] && rm -f $FICHERO_RESUL
     done
    
    }
    
    comunicaciones()
    {
     echo ""
     echo "Fecha de ejecucion del script : `date`"
     echo ""
    
     print "\t\tMaquina\t\t\tEstado"
     print "\t\t=======\t\t\t======"
     print ""
     cat ${DIR_EJE}/bbdd.conf | grep -v "#"| cut -d' ' -f1 | uniq | while read dominio version
     do
            FICHERO_RESUL=${DIR_EJE}/dispon${bbdd}.txt
            [[ -f $FICHERO_RESUL ]] && rm -f $FICHERO_RESUL
            /usr/sbin/ping ${dominio} > $FICHERO_RESUL
            estado=$?
            print "\t\t"${dominio}"\t\t\c"
            if [ $estado -eq 0 ];then
                    msgestado=OK
            else
                    if [ $estado -eq 1 ];then
                            msgestado=ERROR
                    else
                            msgestado=AVISO
                    fi
            fi
            printf $msgestado": "
            tail -1 $FICHERO_RESUL
            [[ -f $FICHERO_RESUL ]] && rm -f $FICHERO_RESUL
     done
    
    }
    
    
    # MAIN
    
    while [ 1 ]
    do
        menu
        echo  "\t\t\tElija una opcion: \c"
        read OPCION
        case ${OPCION} in
             1) disponible
                continua
              ;;
    
             2) comunicaciones
                continua
              ;;
    
             3) tnsping
                continua
              ;;
    
             4) echo ""
                exit 0
              ;;
     [a-z,A-Z]) uso
                continua
              ;;
             *)
              ;;
        esac
    done
    
    exit 0

  5. #5
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    Thus we learn not only shell scripting, but a bit of foreign talk also. It's a real education, this!
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

  6. #6
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    Originally posted by hrishy
    Well the only realy way to check wheather the database is up or not would be to from a shell script taht can actually login into the databse and do somethin like seelect sysdate from dual;
    No need to know any username and or password, no need to actually log into the database to know if it is up and running. Simply try to connect to the database using any existent or non existent database account. If the connection is successfull you know the database is up and running. If you get ORA-1031 "Invalid username or password" you know the database is up and running. In any other case you know the database (or at least one of the needed system components, like listener) is not up and running.
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

  7. #7
    Join Date
    Oct 2000
    Posts
    250
    Thanks for all the valuable responses... I will try it up.

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