time take by a script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

time take by a script

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-14-2004
encrypted's Avatar
encrypted encrypted is offline Forum Advisor  
Registered User
 
Join Date: Feb 2004
Last Activity: 30 November 2011, 9:36 AM EST
Location: Oslo, Norway
Posts: 220
Thanks: 0
Thanked 1 Time in 1 Post
time take by a script

Hi !

I have got a script which takes some time to execute.
Eg. if the script is called test.sh

#!/bin/bash
<command1 to execute>
<command2 to execute>
<command3 to execute>
<command4 to execute>
.
.
.
.
<command n to execute>

At the end of the script I want to show the users the actual time(user NOT CPU) taken for the script to execute. I know of the time
command but where shall I put in the code for calculating the time.
Sponsored Links
    #2  
Old 07-14-2004
s93366's Avatar
s93366 s93366 is offline
Registered User
 
Join Date: Apr 2002
Last Activity: 4 August 2011, 11:04 AM EDT
Location: Sweden / Stockholm
Posts: 168
Thanks: 0
Thanked 1 Time in 1 Post
Hi..

A solution would be to use test.sh to time another shell script with the acctual commands..
---
test.sh
#!/bin/sh
time /path/to/script/sh

---

/Peter
Sponsored Links
    #3  
Old 07-14-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
 
Join Date: Dec 2003
Last Activity: 13 May 2013, 9:02 AM EDT
Location: Melbourne, Australia
Posts: 2,185
Thanks: 3
Thanked 24 Times in 23 Posts

Code:
#!/bin/ksh

time ( command1 && \
           command2 && \
           command3 && \
           commandn )

exit 0

For some reason this won't work with bash nor sh. It works fine and dandy with ksh though.

Peter's solution above is guaranteed to work on all shells so is the solution I'd personally go for.

Ta,
ZB
    #4  
Old 07-14-2004
encrypted's Avatar
encrypted encrypted is offline Forum Advisor  
Registered User
 
Join Date: Feb 2004
Last Activity: 30 November 2011, 9:36 AM EST
Location: Oslo, Norway
Posts: 220
Thanks: 0
Thanked 1 Time in 1 Post
Thanks Peter!

I was expecting a similar solution.

Cheers
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Ftp script hangs for first time,but works every second time selvankj Shell Programming and Scripting 1 05-10-2012 03:45 AM
what would a script include to find CPU's %system time high and user time high? sushwey Shell Programming and Scripting 9 04-26-2012 12:44 PM
Script to convert GMT time to local time Pluff Shell Programming and Scripting 12 06-27-2011 06:47 AM
Shell script to convert epoch time to real time aismann Shell Programming and Scripting 4 04-25-2011 11:09 PM
Running the script from specific time to threshold time Amey Joshi Shell Programming and Scripting 5 06-19-2009 03:37 AM



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