|
Home > Archive > Unix Programming > August 2006 > Spool To Datestamped File - Newbie Question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Spool To Datestamped File - Newbie Question
|
|
| Mark Smith 2006-08-22, 7:35 pm |
| 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.
| |
| Chris F.A. Johnson 2006-08-22, 7:35 pm |
| 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 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.
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
| |
| carleton.vaughn@gmail.com 2006-08-24, 7:26 am |
| 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 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.
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.
|
|
|
|
|