Reputation: 681
If we run a shell/perl/tcl script in Unix how can we display the percentage of execution in the mean time?
Example:
./scriptname
1% Completed the execution of script.pl
2% Completed the execution of script.pl
...
100% Completed the the execution of script.pl
and display the execution time taken for the script at the end.
Example output:
Execution time for script.pl is :50 Seconds
Upvotes: 1
Views: 1651
Reputation: 7516
In Perl, look at the Smart::Comments module.
And for the elapsed time, simply take the delta of the time()
at the beginning versus the end.
Upvotes: 4
Reputation: 161644
#!/bin/bash
before=`date +%s`
# do task
for i in {1..10}; do
# do steps
sleep 1
# show progress
echo -ne "${i}0% Completed\r"
done
after=`date +%s`
duration=$((after-before))
echo "Execution time is: $duration Seconds"
Upvotes: 1
Reputation: 2068
as the time a script executes may differ each time (slightly), you need to do this from your script only, as the shell doesn't offer this feature.
i'd recommend to set some "milestones" after each function call or whatever step in your script with an integer that is increased each time by 1 or 0.x
this one may be tough, but it's the only way as far as i'm concerned.
Upvotes: 0
Reputation: 106385
We've implemented similar progress display with Time::Progress module, perhaps you'd check it.
Upvotes: 1
Reputation: 81684
There are only two ways you could do this:
bash
, tclsh
, or perl
do, so you're out of luck.Only the second one is generally applicable. Sorry.
Upvotes: 0