Skip to Main Content
  • Questions
  • shell script to send two outputs to single file

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, nagasuresh.

Asked: June 28, 2016 - 3:24 pm UTC

Last updated: June 29, 2016 - 4:32 am UTC

Version: 11g

Viewed 1000+ times

You Asked

Hi Tom,

I need to prepare one shell script, which contains start and end time of the script(which is another shell script) and one database query.
In this script, i am good to execute the db query and send output to file.In the same way,i want to append the start and end time of the another script to the same file. please guide me .





and Connor said...

Are you using SQL Plus ? If so, then you can use spool and append,

SQL> help spool

 SPOOL
 -----

 Stores query results in a file, or optionally sends the file to a printer.

 SPO[OL] [file_name[.ext] [CRE[ATE] | REP[LACE] | APP[END]] | OFF | OUT]


So your shell script can write the start time to a file, then your query can do "spool append" to the same file, and then your shell script can append the end time to the file.

eg

echo `date` > /tmp/myfile.dat
sqlplus @my_query.sql
echo `date` >> /tmp/myfile.dat


where "myquery.sql" would contain:

spool /tmp/myfile.dat append

Is that what you are after ?

Is this answer out of date? If it is, please let us know via a Comment