다음 함수를 사용하여 루트 사용자로 sqlplus 출력을 unix 변수에 할당하려고 합니다.
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';")
하지만 다음과 같은 오류가 발생합니다
[root@xxxxxx tmp]# SPFILE=$(sql "select value from v\$parameter where name = 'spfile';")
-bash: /bin/sqlplus: No such file or directory