Spool To Datestamped File - Newbie Question
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Spool To Datestamped File - Newbie Question




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Spool To Datestamped File - Newbie Question  
Mark Smith


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-23-06 12:35 AM

Hi everyone.  I am a unix newbie, so I apologize for the simple question.  I
have a simple sql script, say db_query.sql, which runs a select against one
of our Oracle databases.  How do I write a unix script which will kick off
the sql script and spool the output to a datestamped file?  Thanks a lot in
advance.







[ Post a follow-up to this message ]



    Re: Spool To Datestamped File - Newbie Question  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-23-06 12:35 AM

On 2006-08-22, Mark Smith wrote:
> Hi everyone.  I am a unix newbie, so I apologize for the simple question. 
 I
> have a simple sql script, say db_query.sql, which runs a select against on
e
> of our Oracle databases.  How do I write a unix script which will kick off
> the sql script and spool the output to a datestamped file?  Thanks a lot i
n
> advance.

file=db_query_$(date +%Y-%m-%d.%H.%M.%S) ## adjust format to taste
db_query.sql > "$file"


--
Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
Shell Scripting Recipes:     |  My code in this post, if any,
A Problem-Solution Approach  |         is released under the
2005, Apress                 |    GNU General Public Licence





[ Post a follow-up to this message ]



    Re: Spool To Datestamped File - Newbie Question  
carleton.vaughn@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-24-06 12:26 PM

Mark Smith wrote:
> Hi everyone.  I am a unix newbie, so I apologize for the simple question. 
 I
> have a simple sql script, say db_query.sql, which runs a select against on
e
> of our Oracle databases.  How do I write a unix script which will kick off
> the sql script and spool the output to a datestamped file?  Thanks a lot i
n
> advance.

When you say "datestamped" I'm guessing you mean the datestamp is part
of the filename?

It was pointed out before but the line

timestamp=$(date +%Y-%m-%d.%H.%M.%S)

will set the shell variable "timestamp" to the current time in the form
"2006-08-24.07.51.54".  The construct $(...) will create a string
containing the program's output.

Now it's just a matter of sending sqlplus's output to a file with your
datestamp imbedded in the name:

outfile=db_query-${timestamp}.out
sqlplus db_query.sql > $outfile

This will redirect what sqlplus sends to the standard output into the
file.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:10 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register