Solved

Run sql statement in Unix script

Posted on 2007-04-03
9
2,924 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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

679 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