Re: Run command on sqlplus repetitively without reconnection

  • From: "Senthil Subramanian" <skumar.sen@xxxxxxxxx>
  • To: oradbt054@xxxxxxxxx
  • Date: Fri, 18 May 2007 21:49:24 -0400

You could try 'print -p exit; exit;' in the trap command to exit gracefully
from both SQL*Plus and the shell.



On 5/18/07, David Taft <oradbt054@xxxxxxxxx> wrote:


This shell corprocess feature is very cool.  Something new for my script
toolbox.  Thanks for posting it.

I finally got around to playing with it on AIX 5.2 and found it works with
the Bourne and Korn as well as ksh93 (Enhanced Korn).  Below is a script I
based on your posting.  The trap I've used works, but gives the following
output after doing a CTL-C.

Error 45 initializing SQL*Plus
Internal error

The shell goes away as well as the Oracle session, but I am wondering if
there is a more graceful way I should be using to shutdown the coprocess
jobs.  I couldn't figure it out from googling, nor from the AIX
documentation.  It is not a big deal, but any insight you or someone else
may have would be welcomed.


David Taft




# query co-process test.
# Runs sqlplus query repeatedly in background without reconnection, but
# displays output to screen.
# CTL-C to break (end).
# Intercept every signal relevent to the shell except 9 to exit.
trap 'kill %2;exit' 1 2 3 15

sqlplus -s "/ as sysdba"|&

while :
  print -p "set pagesize 999 linesize 120;"
  print -p "col status format a10"
  print -p "col EVENT format a30 word_wrapped"
  print -p "col sid format 9999"
  print -p "col NAME format a25"
  FROM v\$session_wait w,v\$session s \
  WHERE w.sid = s.sid AND s.username != 'SYS' \
  AND w.event != 'SQL*Net message from client' \
  ORDER BY s.status,w.event,w.state,s.sid;"
  sleep 5
done &

while :
  read -p
  echo "$REPLY"


From: "Radoulov, Dimitre"

With ksh93 (and pdksh, on Linux for example) you can use co-processes

Other related posts: