Solved

Run sql statement in Unix script

Posted on 2007-04-03
9
2,928 Views
Last Modified: 2013-12-21
I am editing a Unix script that logs into the database and executes a sql script in a certain directory. Rather than execute this sql script I want to be able to run sql statement within the unix script. How do I do this.
This is the line in the Unix script:
su - oracle -c "export ORACLE_SID=${db}; sqlplus '/as sysdba' @${PWD}/audit_loc.sql" > ${PWD}/audit_loc.txt

The script is audit_loc.sql

I would like to execute the sql statement within Unix rather than using this: @${PWD}/audit_loc.sql

The contents of the script is the following:
set heading off;
show parameter audit_file_dest;
exit;

0
Comment
Question by:sikyala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 7

Expert Comment

by:nixfreak
ID: 18845021
Not sure but try:
/bin/echo "set heading off;\nshow parameter audit_file_dest;\nexit;" | su - oracle -c "export ORACLE_SID=${db}; sqlplus '/as sysdba' @/dev/stdin" > ${PWD}/audit_loc.txt
0
 
LVL 7

Expert Comment

by:nixfreak
ID: 18845044
Small correction, please try:

/bin/echo "set heading off;\nshow parameter audit_file_dest;\nexit;\n" | su - oracle -c "export ORACLE_SID=${db}; sqlplus '/as sysdba' @/dev/stdin" > ${PWD}/audit_loc.txt
0
 

Author Comment

by:sikyala
ID: 18846363
I tried it and it didn't work. what does @/dev/stdin do?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 7

Expert Comment

by:nixfreak
ID: 18847353
Hi sikyala,

Sorry, please try this modification:

su - oracle -c "export ORACLE_SID=${db}; /bin/echo "set heading off;\nshow parameter audit_file_dest;\nexit;\n" | sqlplus '/as sysdba' @/dev/stdin" > ${PWD}/audit_loc.txt
0
 
LVL 7

Expert Comment

by:nixfreak
ID: 18847406
/dev/stdin can be used with commands that are not designed to take standard input (stdin).

If it still doesn't work perhaps you can also try replacing the single quotes with double quotes surrounding "/as sysdba".
0
 
LVL 7

Expert Comment

by:nixfreak
ID: 18847433
Also I realized that "\n" is not required after exit.
0
 

Author Comment

by:sikyala
ID: 18848132
I tried and got the following:

./audit.bash: nshow: command not found
./audit.bash: nexit | sqlplus '/as sysdba' @/dev/stdin: No such file or directory
0
 
LVL 7

Accepted Solution

by:
nixfreak earned 500 total points
ID: 18848730
Ok,
I think the double quotes were causing the problem. So, try:

su - oracle -c "export ORACLE_SID=${db}; /bin/echo 'set heading off;\nshow parameter audit_file_dest;\nexit;' | sqlplus '/as sysdba' @/dev/stdin" > ${PWD}/audit_loc.txt       
0
 

Author Comment

by:sikyala
ID: 18851294
It worked thanks!
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL query for highest sequence 4 73
Loading flat file data in tables 2 97
Oracle Mulit-site configuration 28 68
update based on the value on another table 8 38
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to recover a database from a user managed backup
Suggested Courses

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question