When scripting in bash or any other shell in *NIX, while running a command that will take more than a few seconds, a progress bar is needed.
For example, copying a big file, opening a big tar file.
What ways do you recommend to add progress bars to shell scripts?
I prefer to use dialog with the --gauge param. Is used very often in .deb package installations and other basic configuration stuff of many distros. So you don't need to reinvent the wheel... again
Just put an int value from 1 to 100 @stdin. One basic and silly example:
I have this /bin/Wait file (with chmod u+x perms) for cooking purposes :P
So I can put:
Wait "34 min" "warm up the oven"
or
Wait "dec 31" "happy new year"
Based on the work of Edouard Lopez, I created a progress bar that fits the size of the screen, whatever it is. Check it out.
It's also posted on Git Hub.
Enjoy
I have built on the answer provided by fearside
This connects to an Oracle database to retrieve the progress of an RMAN restore.
Got an easy progress bar function that i wrote the other day:
Or snag it from,
https://github.com/fearside/ProgressBar/
I was looking for something more sexy than the selected answer, so did my own script.
Preview
Source
I put it on github
progress-bar.sh
Usage
My solution displays the percentage of the tarball that is currently being uncompressed and written. I use this when writing out 2GB root filesystem images. You really need a progress bar for these things. What I do is use
gzip --list
to get the total uncompressed size of the tarball. From that I calculate the blocking-factor needed to divide the file into 100 parts. Finally, I print a checkpoint message for each block. For a 2GB file this gives about 10MB a block. If that is too big then you can divide the BLOCKING_FACTOR by 10 or 100, but then it's harder to print pretty output in terms of a percentage.Assuming you are using Bash then you can use the following shell function