0

I want to add progress bar while giving the percentage of the function to be completed such as [===> ] 20% completed. For example, I have a code which uses iperf and I give the time duration that I want.

function Throughput_test()
{
    iperf -c $otherIP -u -b 1000m -t 10 -i1 
 # Here is where I want to add the progress bar. 
 # This function takes 10seconds and I want to 
 # see the progress bar.
}
Grisha Levit
  • 8,194
  • 2
  • 38
  • 53
user3683697
  • 13
  • 1
  • 5

1 Answers1

0

pv and dialog (or xdialog or zenity) may be useful here.

  • pv sits in the middle of a pipe-based operation, counting the data that goes through the pipe and drawing a progress bar based on the expected number of lines/characters of transferred data.
  • dialog is a fairly-comprehensive GUI tool for shell scripts, with xdialog and zenity as X and Gnome equivalents. Sending well-formatted data into stdin allows you to create an updatable progress bar, but sending the right format can be tricky.
  • You can write your own custom dialog using printf, echo -n, and so forth; that's just a matter of outputting the characters one at a time using your own math. You can send the cursor to an already-drawn part of the screen using tput or by echoing \r (carriage return, as opposed to newline).
Jeff Bowman
  • 90,959
  • 16
  • 217
  • 251
  • Hello, can you give me a quick demonstration of pv. What I can do is not completely working. As an example I am trying: `my_function 10 | pv > /dev/null`. _my_function_ part gets input 10 to run 10 seconds and I want to print pv session accordingly. Thanks – user3683697 Aug 19 '15 at 08:56