This discussion is archived
11 Replies Latest reply: Nov 2, 2013 8:58 AM by Mark D Powell RSS

Enter choice at login

user10745179 Newbie
Currently Being Moderated

Hi

 

I have created choice script at oracle login as i have inistalled 2 versions of oracle on the server

1 is for oracle 10g

2 is for oracle 11g

 

When i use su - oracle

It displays like this

 

oracle's Password:

 

 

            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                                   Database options

 

 

                          1)  DATABASE 10g

 

                          2)  DATABASE 11g

 

            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

 

                    Enter Choice:

 

But at the time of backup throgh shell script how can i pass values 1 & 2

Please provide me syntax as

 

su - oracle parameter to chose oracle 10g or oracle 11g in shell script.

 

 

Thanks

Devesh

  • 1. Re: Enter choice at login
    Ramin Hashimzadeh Expert
    Currently Being Moderated

    export ORACLE_HOME

    export ORACLE_SID

     

    ----

    Ramin Hashimzade

  • 2. Re: Enter choice at login
    user10745179 Newbie
    Currently Being Moderated

    Hi Ramin,

     

    In backup script from root it logins to oracle as su - oracle

    we have to provide the input automatically for enter choice.

     

    Thanks

  • 3. Re: Enter choice at login
    Anar Godjaev Expert
    Currently Being Moderated

    Hi,

     

    export ORACLE_HOME

    export ORACLE_SID

     

    For example:

     

    echo " Please connect database"
    echo " "
    echo " 1  -->   DATABASE 10g "
    echo " 2  -->   DATABASE 10g "
    echo " "
    read OPTION
    case $OPTION in
    1)
            ORACLE_SID=DATABASE 10g;export ORACLE_SID
            bash
            ;;
    2)
            ORACLE_SID=DATABASE 11g;export ORACLE_SID
            bash
            ;;
            bash

            TNS_ADMIN=$ORACLE_HOME/network/admin
            export TNS_ADMIN

            LD_LIBRARY_PATH_64=$ORACLE_HOME/lib
            export LD_LIBRARY_PATH_64

            EXTPROC_DLLS=ANY
            export EXTPROC_DLLS
            ;;

    ...............................................

    Thank you

  • 4. Re: Enter choice at login
    user10745179 Newbie
    Currently Being Moderated

    Hi I have already have this script

    i want to enter the 1 & 2 throgh backup shell script my command is

     

    su - oracle -c /apps/oracle/dbbackup.sh


    so want to add 1 & 2 in above command


    Thanks

  • 5. Re: Enter choice at login
    Ramin Hashimzadeh Expert
    Currently Being Moderated

    example for bat file

    http://www.sql.ru/forum/actualutils.aspx?action=gotomsg&tid=1049363&msg=14880604

    Look only scripts

    backupCold.bat

    backupCold.scr

    As you see in bat file you can set or export ORACLE variables.


    ----

    Ramin Hashimzade

  • 6. Re: Enter choice at login
    user3318449 Newbie
    Currently Being Moderated

    Assume you have defined ORACLE_SID then use following line in your shell script

    su oracle -c "/bin/sh /u01/scripts/start_db.sh $ORACLE_SID"

  • 7. Re: Enter choice at login
    user10745179 Newbie
    Currently Being Moderated

    Hi Ramin,

     

    As i mentioned we are using AIX

     

    & after su - oracle we have enter the choice 1 or 2

    my question is how can i pass 1 or 2 in below script.

    export ORACLE_HOME

    export ORACLE_SID is already set in choice, just want to pass values 1 or 2 in below script

     

     

    su - oracle -c /apps/oracle/dbbackup.sh


    Thanks

  • 8. Re: Enter choice at login
    AmitGargOCE Explorer
    Currently Being Moderated

    I know selecting choice 1 or 2 are simple shell scripting options. I will suggest using crontab to schedule backups.

     

    crontab -e

    12 * * * * su - oracle -c /apps/oracle/dbbackup1.sh > /apps/oracle/dbbackup1.log

    11 * * * * su - oracle -c /apps/oracle/dbbackup2.sh > /apps/oracle/dbbackup2.log

     

    Have different HOME & SID in each script.

    export ORACLE_HOME

    export ORACLE_SID

     

    Thanks

    Amit Garg

    www.otnblogs.com

  • 9. Re: Enter choice at login
    EdStevens Guru
    Currently Being Moderated

    I would consider the concept of your 'logon script' itself to be flawed.  As you have discovered, it forces any connecting session to be interactive, and to what end?  Suppose I log on and make a selection, then once logged on and the environment set for that that selection, I need to work with the other database?  How do you get the environment reset at that point?  Surely you don't log off and log back on just so you can take the other choice from your logon script.

     

    Bottom line, I'd lose that script and learn to use the oracle-supplied utility 'oraenv'.  When you do that, your posted problems disappears.

  • 10. Re: Enter choice at login
    DK2010 Guru
    Currently Being Moderated

    Hi,

     

    You can use the if statement in  your shell pass the option 1 or 2(or 10g /11g) as per the option set your Environment  variable there.

    and then you can use your script like

     

    su - oracle -c /apps/oracle/dbbackup.sh 10g

    su - oracle -c /apps/oracle/dbbackup.sh 11g

    Add something like that in your existing script

    env_opt=$1

    if [[ env_opt == 11g ]] ; then

    export ORACLE_HOME=<>

    export ORACLE_SID=<>

    export PATH=$ORACLE_HOME/bin:$PATH

    fi

    if [[ env_opt == 10g ]] ; then

    export ORACLE_HOME=<>

    export ORACLE_SID=<>

    export PATH=$ORACLE_HOME/bin:$PATH

     

    fi

     

    HTH



  • 11. Re: Enter choice at login
    Mark D Powell Guru
    Currently Being Moderated

    I have to agree with Ed on the idea on having a logon script for the Oracle user.  We have such a script for end users but it sets the Oracle environment and invokes the application for the customer.  Only DBA's should be using the Oracle account and a DBA should just be able to invoke oraenv or a local script to set the Oracle account environment for the version of Oracle you want to connect to.

    - -

    I can remember installing Oracle years ago on VMS and one of the first requirements listed in the Installation manual was to unset all environment variables before invoking the installer.  A script like the can actually cause way more trouble than benefit in some cases.

    - -

    IMHO -- Mark D Powell --

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points