1,105,363 Community Members

Timing for running a script

Member Avatar
manish250
Junior Poster in Training
88 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello all


I am running a shell script.What a need is i want to set a timer which show how much time is elapsed and how much time is left for completing the script.

can it possible in Linux shell scripting.

Member Avatar
griswolf
Veteran Poster
1,144 posts since Apr 2010
Reputation Points: 303 [?]
Q&As Helped to Solve: 264 [?]
Skill Endorsements: 3 [?]
 
0
 

How would you like to display that information from a script? Unless you are willing to learn how to send fancy commands to the terminal, doing 'time remaining' means writing yet another line... Not a recipe for making pretty output.

Member Avatar
manish250
Junior Poster in Training
88 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

How would you like to display that information from a script? Unless you are willing to learn how to send fancy commands to the terminal, doing 'time remaining' means writing yet another line... Not a recipe for making pretty output.

please give any idea what command can be used

Member Avatar
griswolf
Veteran Poster
1,144 posts since Apr 2010
Reputation Points: 303 [?]
Q&As Helped to Solve: 264 [?]
Skill Endorsements: 3 [?]
 
0
 

Assuming a *nix OS because you use the words "shell script".

Internal to the script, you can use date which can be given a format specification. Used, for instance, at the top of a loop, you can compare initial with subsequent values and calculate the difference. From the man page:

SYNOPSIS
date [-ju] [-r seconds] [-v [+|-]val[ymwdHMS]] ... [+output_fmt]
date [-jnu] [[[mm]dd]HH]MM[[cc]yy][.ss]
date [-jnu] -f input_fmt new_date [+output_fmt]
date [-d dst] [-t minutes_west]

DESCRIPTION
When invoked without arguments, the date utility displays the current
date and time. Otherwise, depending on the options specified, date will
set the date and time or print it in a user-defined way.
((NOTE however the +output_fmt option which does not try to set the date))

External to the script use the time command with output that can also be (slightly) configured. From the man page:

SYNOPSIS
time [-lp] utility

DESCRIPTION
The time utility executes and times utility. After the utility finishes,
time writes the total time elapsed, the time consumed by system overhead,
and the time used to execute utility to the standard error stream. Times
are reported in seconds.

Member Avatar
kristo5747
Light Poster
28 posts since May 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

How about

echo "`date '+%m/%d/%y %T:'` START"
echo "do something here"
echo "`date '+%m/%d/%y %T:'` END"

?? This will output like this

03/17/11 20:43:54: START
do something here
03/17/11 20:43:55: END

HTH.

Member Avatar
manish250
Junior Poster in Training
88 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

How about

echo "`date '+%m/%d/%y %T:'` START"
echo "do something here"
echo "`date '+%m/%d/%y %T:'` END"

?? This will output like this

03/17/11 20:43:54: START
do something here
03/17/11 20:43:55: END

HTH.

I want to show the progress bar for the script

Member Avatar
kristo5747
Light Poster
28 posts since May 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

A progress bar? Mmmm...Google search

http://www.google.com/search?q=progress+bar+in+bash

gives me this top URL: http://www.theiling.de/projects/bar.html

Have fun.

Member Avatar
griswolf
Veteran Poster
1,144 posts since Apr 2010
Reputation Points: 303 [?]
Q&As Helped to Solve: 264 [?]
Skill Endorsements: 3 [?]
 
0
 

A progress bar? Mmmm...Google search

http://www.google.com/search?q=progress+bar+in+bash

gives me this top URL: http://www.theiling.de/projects/bar.html

Have fun.

¡668 lines!

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: