Oracle‎ > ‎

ksh

Storing sqlplus values in ksh variables

# Set desired Oracle environment
export ORAENV_ASK=NO
export ORACLE_SID=foo
. /usr/local/bin/oraenv

db_role=`sqlplus -s "/ as sysdba" <<EOF
        set heading off feedback off verify off pagesize 0
        select database_role from v\\$database;
        exit
EOF`

echo "Testing role of $db_role."

if [[ "$db_role" = "PRIMARY" ]]; then   
        echo "Role is primary"
else #if is a standby role then
        echo "Role is standby"
fi

Result:
$ ./test.sh 
Testing role of PRIMARY.
Role is primary

and from a standby:
$ ./test.sh 
Testing role of PHYSICAL STANDBY.
Role is standby

Comments