The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
C Shell Script query bpupdown Shell Programming and Scripting 1 05-13-2008 07:38 PM
Need Unix script for executing oracle query ravi gongati Shell Programming and Scripting 14 03-24-2008 05:53 AM
Script executing sql query kingluke Shell Programming and Scripting 2 01-23-2008 01:57 PM
executing a SQL query in shell script lijju.mathew Shell Programming and Scripting 1 05-17-2007 11:29 AM
Executing Sql Query Using Shell Script ragha81 Shell Programming and Scripting 14 07-31-2006 02:15 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-22-2002
98_1LE 98_1LE is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2000
Location: Greater Dallas area
Posts: 405
Executing a SQL query from a shell script

I cannot figure out how to run a SQL script, or just a sqlplus query, from a shell script (bash or ksh). Basically, I need to su - oracle from root and run a query, then test the exit status.
  #2 (permalink)  
Old 03-22-2002
Jimbo
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
You want a script to run as root and launch a script in oracle? I think the cleanest way is two separate shell scripts. I tried an embedded su thru an endword (which I do a lot), but I could not capture the status code inside the su - pretty strange.

myroot.sh:
Code:
#!/bin/sh
exec > myroot.out
su - oracle -c scott.sh
exit 0
scott.sh:
Code:
#!/bin/sh
sqlplus -s scott/tiger @ scott.sql
if test $? -ne 0 ; then
   echo 'sqlplus error'
   exit 1
else
   echo 'sqlplus OK'
   exit 0
fi
scott.sql:
Code:
whenever sqlerror exit failure
set termout off
spool scott.lst
select ename from emp;
exit
  #3 (permalink)  
Old 03-22-2002
98_1LE 98_1LE is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2000
Location: Greater Dallas area
Posts: 405
Thank you very much
  #4 (permalink)  
Old 03-23-2002
inpavan inpavan is offline
Registered User
  
 

Join Date: Sep 2001
Posts: 36
Jimbo,

I want to know why you are using myroot.sh when executing scott.sh will do the required job. Are you using myroot.sh to change the user or is it useful in other way?

Say, if I want to run the sql query without su, can I just use scott.sh and dont use myrott.sh?

I tested it and if you run scott.sh, then you get the desired result.

Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0