Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Query - date command

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-25-2013
nag_sathi nag_sathi is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 15 April 2015, 10:21 AM EDT
Location: INDIA
Posts: 63
Thanks: 47
Thanked 1 Time in 1 Post
Query - date command

Hi,

I am trying to capture the total run time of a script which contains SQL's by providing date command in top & bottom, it displaying both the times same in top & bottom.However the time in the sql connection is different.Please help.

OS - LINUX
Shell - ksh



Code:
printf "Script Started at $date" >> $LOGFILE
sqlplus userid/pwd test1.sql
.
.
.
sqlplus userid/pwd testn.sql
printf "Script Ended at $date" >> $LOGFILE

Sponsored Links
    #2  
Old Unix and Linux 03-25-2013
in2nix4life's Unix or Linux Image
in2nix4life in2nix4life is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 21 May 2015, 2:46 PM EDT
Location: East Coast
Posts: 618
Thanks: 1
Thanked 177 Times in 163 Posts
It seems you're storing the date in a variable somewhere in your script which is fine, however, if you need a start and end date then you will need to store the date command again.


Code:
$date=$(date)
printf "Script Started at $date" >> $LOGFILE
sqlplus userid/pwd test1.sql
.
.
.
sqlplus userid/pwd testn.sql
$date=$(date)
printf "Script Ended at $date" >> $LOGFILE

The Following User Says Thank You to in2nix4life For This Useful Post:
nag_sathi (03-25-2013)
Sponsored Links
    #3  
Old Unix and Linux 03-25-2013
radoulov's Unix or Linux Image
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 23 April 2015, 3:05 PM EDT
Location: Варна, България / Milano, Italia
Posts: 5,690
Thanks: 184
Thanked 624 Times in 582 Posts
You could use:

Code:
printf 'Script Started at %s\n' "$( date )" >> $LOGFILE
sqlplus userid/pwd test1.sql
.
.
.
sqlplus userid/pwd testn.sql
printf 'Script Ended at %s\n' "$( date )" >> $LOGFILE

Note that if you add set time on timing on at the top of your SQL commands,
you'll get the current and the elapsed time in your sqlplus output.

Last edited by radoulov; 03-25-2013 at 10:07 AM..
The Following User Says Thank You to radoulov For This Useful Post:
nag_sathi (03-25-2013)
    #4  
Old Unix and Linux 03-25-2013
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 22 May 2015, 10:54 AM EDT
Location: Galactic Empire
Posts: 3,402
Thanks: 240
Thanked 1,216 Times in 1,142 Posts
You can also use time command to print elapsed time for sqlplus utility:

Code:
time sqlplus username/password@instance

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Date Query theref UNIX for Dummies Questions & Answers 2 01-17-2011 08:55 AM
Query regarding date field in shell script kavithakuttyk Shell Programming and Scripting 1 10-03-2009 07:49 AM
Date & NUmber Validation Query alok_jax Shell Programming and Scripting 4 01-05-2005 06:51 PM
Date change related query franklo UNIX for Dummies Questions & Answers 2 09-04-2002 09:41 PM
Unix Date query csong2 UNIX for Advanced & Expert Users 5 10-29-2001 01:58 PM



All times are GMT -4. The time now is 11:20 AM.