progress bar instead of % complete in my for loop
I've got a loop which is able to echo out how complete a process is after each loop (e.g says 25% if the loop has 4 elments and has run once through).
Is there any way I can print characters, perhaps a progress bar? I was thinking of using the percentage as a count or something and using. Code:
I got told off for including code from work here :P |
Lol, ok this is a total mess - %'s are output as follows:
Code:
16% 20% 25% 33% 50% 100% |
Problem here is contributing to the progression of the percentages:
Code:
((STATUS= 100 / COUNT_VMS )) Code:
STATUS=$(( 100 / COUNT_VMS )) Code:
STATUS=$(( COUNT / TOTAL_VMS * 100 )) Code:
STATUS=$(( COUNT * 100 / TOTAL_VMS )) Code:
STATUS=$(( ( COUNT * 100 ) / TOTAL_VMS )) Correcting that calculation should help you address the percents going up wrong; if you're concerned about how they are printing on the screen, you'll want to look into \b and \r for use with `echo -e` and/or `printf` to bring you back to the beginning of the line and print the next value, so it looks like the number is actually counting up in one place. But.... Which do you want in the end - a bar, or the % display? If I remember right, there is an already-made tool or script, probably more than one, which can be adapted to doing a progress bar. If you go looking but cannot find it, I'll have a look. Good luck! :) EDIT & PS - I also note that you appear to be counting progress, in reverse, from NUM_VMS to zero. If I correctly am seeing that, then you might end up with a percent counter that starts at 100 and goes backward! If so, not a big deal, we can fix that easy enough later. |
Quote:
Quote:
Code:
((COUNT_VMS--)) Code:
(( STATUS = 100 / COUNT_VMS )) Quote:
As GGirl has said though, there are plenty of progress bar options around. Maybe have a look at Greg Wooledge's page |
Quote:
Quote:
|
Quote:
Quote:
|
Quote:
|
Doh ... that would be my very bad as I did a typo :(
Change to: Code:
(( MODULO = 100 % COUNT_VMS )) |
Hmmm... starts at 4% and then goes to 84% at the end now :S This is certainly more challenging than I expected. When it's done one task of six it should be at 16% - not 4%. That 'typo' mentioned previously gives better results, I'm gonna have to read this to make sense of it I think :P
|
Well I don't have access to what you are doing so I created a simple for loop and it seems to work as expected, ie for items each is a value of 16 * counter + modulo hence first value
is 20: Code:
#!/bin/bash Code:
20% 36% 52% 68% 84% 100% |
the counter was still 0.
|
Also; my 'bar code' looks like this - it's 90% what I wanted:
Code:
yes "=" | head -n$STATUS | xargs echo -n | tr -d " " Code:
[================20%================36%================52%================68%================84%================100%] |
Who's your daddy :) ... Just kidding, this was kinda fun:
Code:
#!/bin/bash |
That is seriously f*cking cool.
Thanks so much, lol. This is really awesome, just noticed pressing enter doesn't mess it up, I am seriously impressed, thanks! |
nah that's cool ... it was fun :)
I think the true aim would be if you could do it without the clear so you could have other data on screen scrolling through, but for a quick knock up it gets the job done. Cheers |
All times are GMT -5. The time now is 05:15 PM. |