How to get sql command with output in files?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get sql command with output in files?
# 1  
Old 11-07-2013
How to get sql command with output in files?

I tried executing set of queries from shell script but not able to capture the input query in the log file,but the input query is not displayed along with output. Only the outputs are being captured in the log file. Is there a way to capture the input query along with the corresponding input??
# 2  
Old 11-07-2013
Try adding exec > "logfile" 2>&1 to the beginning of your script
# 3  
Old 11-07-2013
is it before the sql connection or after that
# 4  
Old 11-07-2013
These might be a terrible ways, but a few things spring to mind.

You could do something with xargs like:-
Code:
echo " "|xargs -t your required command here

You might so:-
Code:
set -x
your required command here
set +x

Maybe even:-
Code:
echo "your required command here"
your required command here

None of these are necessarily very pretty and I'm happy to be told they are silly, but they were just thoughts.

What have you tried so far and what are you missing?



Robin
Liverpool/Blackburn
UK
# 5  
Old 11-07-2013
hi friends, my concern in when i make sql connection with below command in between i need to run 3-4 queries and i can not use UNIX command in between sql connection, what i need to do in this case.

i am using AIX and ksh shell
# 6  
Old 11-07-2013
Well, you haven't actually given us your code, but I will take a guess:-
Code:
$ sqlplus <<-EOSQL
$userid/$password
select count(*) from user_tables ;
!echo "I've just counted the user tables"
select 1 from dual;
!echo "I've just worked out the number 1 is, erm 1!"
EOSQL

Is this what you are after, or have I missed the point?

If you are after trapping queries that are keyed in, then you are probably looking at Oracle Auditing, a whole project in itself.



Robin
# 7  
Old 11-07-2013
thanks rbatte, yes that what i want bceasue only echo is not working in sql connection.
! before echo work in my script. thanks a lot.,

please let me know one query, what i need to do if i want to use unix command in between sql connection
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies

2. Shell Programming and Scripting

Create Multiple UNIX Files for Multiple SQL Rows output

Dear All, I am trying to write a Unix Script which fires a sql query. The output of the sql query gives multiple rows. Each row should be saved in a separate Unix File. The number of rows of sql output can be variable. I am able save all the rows in one file but in separate files. Any... (14 Replies)
Discussion started by: Rahul_Bhasin
14 Replies

3. Shell Programming and Scripting

Compare 2 files using sdiff command output

Hi All, I have written the shell script which does the following : a. Reads the *.cnf file content from the specified input folder path b. Grep's some strings from the *.cnf file and writes the output in result file(*.cnf_result.txt) in output folder c. Now, if we get new version of... (5 Replies)
Discussion started by: Optimus81
5 Replies

4. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

5. Shell Programming and Scripting

list files command output

Hi All, Below is the 2 different ouputs of the command "ls -lrt", my question is what exactly "total 0" & "total 8" means here ? $ ls -rtl total 0 -rw-r--r-- 1 oracle dba 0 Feb 10 20:16 c -rw-r--r-- 1 oracle dba 0 Feb 10 20:16 b -rw-r--r-- 1... (1 Reply)
Discussion started by: kannan84
1 Replies

6. Shell Programming and Scripting

sql select command output formatting in shell script

Hi, I need to connect to the database and retrieve two variables from the database and store them in a variable,out of these two variables I need to get lastdigit appended to the variable 1 retrieved and variable 2 with out any modification in short select var,data from usage; o/p=... (1 Reply)
Discussion started by: rkrish
1 Replies

7. Shell Programming and Scripting

Unix shell command output to a sql statement

Can i do this Say one command sed 's/:*/ /g' $summf is returning C1234 C2345 C3434 some no of rows, now this ouput i have to insert it into a DB table how do i do this?? (2 Replies)
Discussion started by: depakjan
2 Replies

8. Shell Programming and Scripting

join files cisco command output

We have two files with results of two commands of cisco: one file; showintstatus, have the following format: Gi2/6 servidorlij connected 176 full 1000 10/100/1000BaseTsecond file; showmacaddrestable, have the following format: * 162 0021.9b8d.073e dynamic Yes 0 ... (1 Reply)
Discussion started by: robonet
1 Replies

9. Shell Programming and Scripting

Help! Paste Multiple SQL output result to exec command

Hi, I want to write the shell script to change multple file name (the file name is get from DB) e.g. cp db1.txt file1_new.txt cp db2.txt file2_new.txt cp db3.txt file3_new.txt I have write the script like this: VAR=`sqlplus -s $LOGON @<<ENDOFTEXT set termout off ... (0 Replies)
Discussion started by: jackyntk
0 Replies

10. Shell Programming and Scripting

Execute command created from sql output

Hi, I've would like to create kill statement from sqlplus output. So, I've modified somoene's script : mud_kill_stmt=`sqlplus -s / as sysdba <<EOF select 'kill -9 ' || p.SPID || ';' statement from $process_view p, $session_ ......... and so on exit; EOF` $mud_kill_stmt | tr ... (1 Reply)
Discussion started by: Arkadiusz Masny
1 Replies
Login or Register to Ask a Question