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.

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.

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

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.

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.