Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash progress bar [duplicate]

I'm using the following script to go through a large list of domains in whois and find the registrar (useful for server/DNS migrations) and it works fine.

However I am wanting to incorporate a progress bar into it just for the sake of convenience. Here's my script, if it can be improved let me know:

#!/bin/bash
for f in `cat /var/www/vhosts/domainlist`
 do
   if
   domain=$f
   [ "$domain" ] ;
   then
    whois $f | grep -i domainregistrar > /dev/null
     if
     [ $? -le 0 ] ;
     then
      echo $f >> our_registrar
     else
      echo $f >> external_registrar
     fi
   fi
 done
echo "Done, check our_registrar file."

I've tried this first: http://moblog.bradleyit.com/2010/02/simple-bash-progress-bar-function.html

And then this but with no luck.

What do you reckon is the easiest way to get a progress bar implemented into that script?

like image 750
Zippyduda Avatar asked Jul 21 '12 13:07

Zippyduda


People also ask

How do I copy progress bar in Linux?

pv Command You can use the “pv” command for copying a single file as it provides statistics related to the progress and speed. In the following case, “pv” will output the “inputfile” to “stdout”, which is then redirected to the “outputfile” using the “>”operator.

Does cp command show progress?

While it doesn't display speed, when copying multiple files, the -v option to the cp command will provide you with progress info.


1 Answers

You can use pv but the other way.

 for ... # outer loop
 do
   ...
   echo -n X
 done | pv -s $(wc -l 'your_file_list') - >/dev/null 

so you use echo X to say when another portion of work is done and this is counted by pv, it's know what the whole job size is due to -s option.

like image 99
nshy Avatar answered Sep 23 '22 20:09

nshy