Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2005
    Posts
    26

    Unanswered: oracle environment script issues

    Hi all,

    We use this to get the Oracle Sid and to set ORACLE_HOME in a script. However, when you have two databases (such as TEST and TESTA), it sees two TEST (because it cuts off after 4 characters to remove colon). We can't just set to remove 6 column because most databases have 4 characters. The result is that ORACLE_HOME will look like this : /u00/app/oracle/product/9.2.0 /u00/app/oracle/product/9.2.0.

    Any have any scripting ideas to help?

    Here is our code now that is causing problem:

    export ORATAB=/etc/oratab

    sid1=$1
    sid2=`grep ":Y" /etc/oratab| awk -F: '{print $1}'`
    sid2=`echo $sid2 | colrm 5`

    export ORACLE_SID=${sid1:-${sid2}}

    export ORACLE_HOME=`grep "$ORACLE_SID" $ORATAB | awk -F: '{print $2}'`

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool


    Remove this statement:
    Code:
    sid2=`echo $sid2 | colrm 5`

    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Oct 2005
    Posts
    26

    unfortnuately

    Unfortunately, that does not resolve the issue. Thanks for the suggestion.

  4. #4
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool


    Also, this statement will return ALL databases in the oratab which have a ':Y' in the entry:
    Code:
    sid2=`grep ":Y" /etc/oratab| awk -F: '{print $1}'`
    Therefore if your oratab looks like this:

    TEST:/u00/app/oracle/product/9.2.0:Y
    TESTA:/u00/app/oracle/product/9.2.0:Y
    PROD:/u00/app/oracle/product/9.2.0:Y

    The sid2 variable will look like this:

    TEST TESTA PROD


    PS if your oratab has comment lines (#) they will also appear in the sid2 variable.


    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  5. #5
    Join Date
    May 2004
    Location
    Dominican Republic
    Posts
    721
    Just curious.. but why aren't you using oraenv for this (usually, on $ORACLE_HOME/bin) ? I believe it is what you should use, and thus avoid all this scripting stuff.

    But anyway, if you still want to use a script, I believe that something like
    Code:
    $ cat /etc/oratab
    test:/u00/app/oracle/product/9.2.0:Y
    test4:/u00/app/oracle/product/9.2.0:Y
    $ cat setenv
    #! /usr/bin/ksh
    
    if [[ $# -eq 0 ]];
    then
            echo "You must provide an SID."
            exit 1
    fi
    
    ORACLE_SID=$( awk -v sid=$1 -F: '($1 == sid && $3 == "Y") { print $1 }' /etc/oratab )
    ORACLE_HOME=$( awk -v sid=$1 -F: '($1 == sid && $3 == "Y") { print $2 }' /etc/oratab )
    
    if [[ -z "$ORACLE_SID" ]];
    then
            echo "The SID $1 was not found in /etc/oratab."
            exit 1
    else
            export ORACLE_SID ORACLE_HOME
            exit 0
    fi
    $ ./setenv test
    $ echo $ORACLE_SID
    test
    $ ./setenv test4
    $ echo $ORACLE_SID
    test4
    $ ./setenv does_not_exists
    The SID does_not_exists was not found in /etc/oratab.
    $ ./setenv
    You must provide an SID.
    $
    should work.

Posting Permissions

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