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.
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.
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
griswolf
Veteran Poster
1,176 posts since Apr 2010
Reputation Points: 344
Solved Threads: 262
Skill Endorsements: 1