Co-processes and returns...

From: Adrian Billington (billiauk_at_yahoo.co.uk)
Date: 03/29/05


Date: 29 Mar 2005 01:56:11 -0800

I posted this in C.U.Shell about 6 days ago and had no responses, so
at risk of being accused of cross-posting, I'm trying here instead :o)

Hi,

I am writing a ksh script that is going to run through a directory
full of SQL scripts to be applied to an Oracle database. I'd really
like to do this in a single Oracle session using a coprocess rather
than have each SQL script run in a "HERE-document" which would imply a
new Oracle connection per SQL file.

Below is a really simple template of what I want to do, minus the SQL
file management, but the principle is the same. Here's the script and
I'll explain what it is I'm actually looking for afterwards.

***************************************************
#!/bin/ksh

function open_conn
{
   sqlplus -s |&
   print -p user/pass@db
}

function run_sql
{
   print -p "${1}"
   print -p "prompt END_OF_OUTPUT_STREAM"
   while read -p outstream
   do
      if [[ ! ${outstream} == "END_OF_OUTPUT_STREAM" ]]
      then
         echo "${outstream}"
      else
         break
      fi
   done
}

function close_conn
{
   run_sql "exit"
}

open_conn
run_sql "@create_table.sql"
run_sql "@create_another_table.sql"
run_sql "@create_index.sql"
close_conn

***************************************************

This works OK as a framework. However, I want to build in error
checking but am having difficulty getting the return status of the
coprocess. Capturing $! and using it in the "wait ${bpid}" command
does not work for me because it leaves me hanging. And of course, $?
after the print -p commands tell me the print -p commands were OK.

I need to catch the return code of everything I send to Oracle. The
output stream terminator only works as long as I can get to the end of
a script or statement being sent down the pipe. So I'm not sure if
there's an answer to this other than use a HERE document...

TIA
Adrian



Relevant Pages

  • Return status of coprocess
    ... I am writing a ksh script that is going to run through a directory ... full of SQL scripts to be applied to an Oracle database. ... after the print -p commands tell me the print -p commands were OK. ...
    (comp.unix.shell)
  • Re: What the F***. Cant SSH do this?
    ... We cannot telnet or SSH as user 'oracle'. ... then set user to oracle once we are on the remote system. ... I need to write a script that will automatically SSH to the remote ... system, then set user to oracle, run a few commands (waiting for them ...
    (comp.unix.shell)
  • tracking back files in .sh_history file
    ... I am seeing excessive commands in the history file for the oracle ... script could be generating these commands over and over. ... Is there any way we can trace back the commands in the history file to ...
    (comp.unix.shell)
  • =?ISO-8859-1?Q?New_System_Command_Script_Facility?=
    ... I'm currently finished writing a new replacement command script processor ... (at least that RACF thinks so, and better support for non-RACF sites). ... The IF-type commands now have ELSE processing ... non-scroll highlighted console message and BEEP until a specific JOB or TASK ...
    (bit.listserv.ibm-main)
  • Re: Command Line Interface
    ... >> should accept system commands only for an administrator. ... >> how should I supress the bash shell and launch my custom CLI ... > The script could run in a restricted shell and offer a menu of ... account, and either 1) change account password, 2) ...
    (comp.os.linux.misc)