We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Timing for running a script

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.

3
Contributors
7
Replies
1 Day
Discussion Span
2 Years Ago
Last Updated
8
Views
manish250
Junior Poster in Training
88 posts since Aug 2008
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 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.

griswolf
Veteran Poster
1,176 posts since Apr 2010
Reputation Points: 344
Solved Threads: 262
Skill Endorsements: 1

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

manish250
Junior Poster in Training
88 posts since Aug 2008
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 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.

griswolf
Veteran Poster
1,176 posts since Apr 2010
Reputation Points: 344
Solved Threads: 262
Skill Endorsements: 1

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.

kristo5747
Light Poster
28 posts since May 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

manish250
Junior Poster in Training
88 posts since Aug 2008
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 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.

kristo5747
Light Poster
28 posts since May 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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!

griswolf
Veteran Poster
1,176 posts since Apr 2010
Reputation Points: 344
Solved Threads: 262
Skill Endorsements: 1

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0762 seconds using 2.66MB