Go Back   The UNIX and Linux Forums > Operating Systems > Linux
google site



Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-11-2010
Registered User
 

Join Date: Mar 2010
Location: Mumbai
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation set echo off command issue

Hi all,
I am executing a Oracle SQL statement in a shell script and spooling the output of the query into a File with spool command.
I want to ensure that only output of the query appears in file excluding the SQL statement but even set echo off command is not working.
Please help
Sponsored Links
  #2  
Old 03-11-2010
Registered User
 

Join Date: Oct 2009
Location: St. Louis, MO
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Here's what I do...


Code:
sqlplus -s /nolog <<-EOF
   whenever oserror exit failure
   whenever sqlerror exit failure rollback
   set heading off pagesize 0 feedback off linesize 400
   set trimout on trimspool on termout off echo off sqlprompt ''

   connect $SQLUSER/$SQLPWD@$DB

   spool $spoolfile

   select * from mytable;

   spool off

   exit

EOF


Last edited by jsmithstl; 03-11-2010 at 09:11 AM.. Reason: added spool commands
  #3  
Old 03-11-2010
Registered User
 

Join Date: Mar 2010
Location: Mumbai
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Jsmithstl,
I am using spool command to write the output of the query in a file
But Query appears in the file along with the Query output.
I just want the output of the query in the file.
Ex: this is what currently apperas in the file test.txt=>
SELECT COUNT(*) FROM USER_TAB_COLUMNS RET WHERE RET.COLUMN_NAME ='EMPLOYEE_ID';

4

spool off;

But what is want the file to contain is just the output of the above written query i.e: 4
How do i go about it using spool command as even the statement echo off doesnt seem to work
  #4  
Old 03-11-2010
radoulov's Avatar
--
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 3,619
Thanks: 15
Thanked 55 Times in 54 Posts
Please post the code you're using.
  #5  
Old 03-11-2010
Registered User
 

Join Date: Mar 2010
Location: Mumbai
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
i tried the script attached by you.
And it worked thanks a lot!!!!!!!!
By the way Jsmithstl i would be highly obliged if you can tell me what part of the code provided by you prevented the query from being printed in the spooled file.
Please do reply to this ping cause it would be really helpful
  #6  
Old 03-11-2010
Registered User
 

Join Date: Oct 2009
Location: St. Louis, MO
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
It works for me:

CODE:

Code:
$ cat tsql.ksh
#!/usr/bin/ksh

. ~/.profile

SQLUSER=xxxxxxx
SQLPWD=xxxxxxx
DB=mydb

SPOOLFILE=blah.out

sqlplus -s /nolog <<-EOF
   whenever oserror exit failure
   whenever sqlerror exit failure rollback
   set heading off pagesize 0 feedback off linesize 400
   set trimout on trimspool on termout off echo off sqlprompt ''

   connect $SQLUSER/$SQLPWD@$DB

   spool $SPOOLFILE

   select 'I only see my query output' from dual;

   spool off

   exit

EOF

exit

RESULTS:

Code:
$ ./tsql.ksh
I only see my query output

$ cat blah.out
I only see my query output

$



---------- Post updated at 08:55 AM ---------- Previous update was at 08:53 AM ----------

These lines:

Code:
   set heading off pagesize 0 feedback off linesize 400
   set trimout on trimspool on termout off echo off sqlprompt ''

  #7  
Old 03-13-2010
Registered User
 

Join Date: Mar 2010
Location: Mumbai
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
set echo off command issue

Hi Smith,
Sorry for the late response.
First things first i need to thank you for the timely help.
Yes you are write it works and the reason for the same is cause sqlplus runs in silent mode i.e. sqlplus -S[ilent] which printing of all command execution steps are supressed though one thing still baffles me why doesnt set echo off command work????

Again thanks for your quick response and hope that i would prove to you all of some help in future.
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
What does following echo command do? akash_mahakode Shell Programming and Scripting 1 11-16-2009 03:56 AM
echo command and piping rushhour UNIX for Dummies Questions & Answers 4 02-16-2009 02:06 PM
Echo command with $$ $# $@ howdy UNIX for Dummies Questions & Answers 3 11-18-2008 03:32 PM
echo statement issue subin_bala Shell Programming and Scripting 3 04-24-2008 02:13 AM
Nested Echo Command Help findprakash UNIX for Dummies Questions & Answers 2 09-22-2007 12:26 AM



All times are GMT -4. The time now is 07:38 AM.