Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Re: Shell scripting
Actually Jared, you can by setting up a sqlplus coprocess and using unix
pipes. The routine below will get a parameter from the v$parameter table
using sqlplus.
Kevin
get_db_parm()
{
unset vRETURNED_PARM
unset vRESPONSE
typeset -u vPARM
vPARM=$1
sqlplus -silent /NOLOG |&
print -p 'set feedback off' print -p 'set echo off' print -p 'set heading off' print -p 'set pagesize 0' print -p 'connect internal'
read -p vRESPONSE
while [ "${vRESPONSE:-Z}" != 'Connected.' -a \
"${vRESPONSE%ORA*}Z" != 'Z' ]
do
read -p vRESPONSE
done
if [ "${vRESPONSE:-Z}" = Z ] ; then
return 1
fi
vTERMINATOR='ZZZZZ'
print -p "SELECT UPPER(name)||':'||value t FROM v\$parameter" print -p "WHERE UPPER(name) = '"${vPARM}"'" print -p "UNION" print -p "SELECT '${vTERMINATOR}' t FROM dual" print -p "ORDER BY 1;"
read -p vRESPONSE
while [ "${vRESPONSE}" != ${vTERMINATOR} ]
do
if [ "${vRESPONSE%%:*}" = $vPARM ] ; then
vRETURNED_PARM=${vRESPONSE##*:} if [ "${vRETURNED_PARM%%\?*}Z" = Z ] ; then vRETURNED_PARM=${ORACLE_HOME}${vRETURNED_PARM#\?} fi
print -p "exit"
# Flush Buffer after exiting
while [ $? -eq 0 ]
do
read -p $vRESPONSE
done
vRETURNED_PARM=`echo $vRETURNED_PARM|sed "s/%/%%/g"`
printf "${vRETURNED_PARM}\n"
return 0
}
-----Original Message-----
Sent: Tuesday, October 08, 2002 10:24 AM
To: Multiple recipients of list ORACLE-L
Omar,
If what you mean is:
"How do I send a value from sqlplus plus directly to a variable in my shell environment?"
You can't.
What you've done is the way it is usually done.
Another way to do it is to use the '&|' korn shell mechanism.
e.g.
sqlplus -silent scott/tiger@$ORACLE_SID |&
This allows you to send commands straight to sqlplus from the ksh command line, and retrieve the results of queries from the cmd line.
It's not as easy as it appears. I wrote a set of shell functions once upon a time to do this, and it gets more complex than you expect.
The method you are currently using works ok.
Of course, you could use Perl with DBI and avoid all this subshell nonsense.
Jared
On Tuesday 08 October 2002 01:23, Cyril Thankappan wrote:
> Sure
>
>
>
>
-- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Jared Still INET: jkstill_at_cybcon.com Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). -- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Kevin Lange INET: kgel_at_ppoone.com Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Tue Oct 08 2002 - 11:23:35 CDT