0

I am trying to assign sqlplus output to unix variable as a root user using the following function

function sql {
su - oracle -c "
 export ORACLE_HOME=$( "`grep "OraG" /u01/app/oraInventory/ContentsXML/inventory.xml | awk '{print $3}'|  cut -d= -f2 | sed 's/\"//g'`"/bin/crsctl status resource -w "((TYPE = ora.database.type) AND (LAST_SERVER = $(hostname -s)))" -f | grep ^ORACLE_HOME= | awk -F= '{ print $2 }' )

   export ORACLE_SID=$( "`grep "OraG" /u01/app/oraInventory/ContentsXML/inventory.xml | awk '{print $3}'|  cut -d= -f2 | sed 's/\"//g'`"/bin/crsctl status resource -w "((TYPE = ora.database.type) AND (LAST_SERVER = $(hostname -s)))" -f | grep ^USR_ORA_INST_NAME= | awk -F= '{ print $2 }' )

   export PATH=$PATH:$ORACLE_HOME/bin

   SQL_OUTPUT=$( $ORACLE_HOME/bin/sqlplus -s / as sysdba<< OCI2
   connect / as sysdba
   set heading off
   set feedback off
   set linesize 145
   set linesize 145
   set feedback off
   spool /tmp/sqlplus.log
   $1
   spool off
   exit
OCI2
   )
   echo "$SQL_OUTPUT"| grep -v \^$
"
}

SPFILE=$(sql "select value from v\$parameter where name = 'spfile';")

but getting the following error

[root@xxxxxx tmp]# SPFILE=$(sql "select value from v\$parameter where name = 'spfile';")
-bash: /bin/sqlplus: No such file or directory
3
  • 1
    Your ORACLE_HOME variable is not being set or being set to a NULL value and therefore it is looking for the sqlplus binary in /bin/sqlplus where it does not exist.
    – jesse_b
    Commented Jul 25, 2019 at 17:45
  • 2
    given that you're calling $ORACLE_HOME/bin/sqlplus and the error is reporting bash: /bin/sqlplus: No such file or directory, it seems to follow that $ORACLE_HOME is not getting set; can you confirm the inner commands of export ORACLE_HOME...?
    – Jeff Schaller
    Commented Jul 25, 2019 at 17:46
  • tried to echo $ORACE_HOME.$ORACLE_SID, but no luck..any idea how to confirm inner export output? Commented Jul 25, 2019 at 18:26

0

You must log in to answer this question.

Browse other questions tagged .