Tracking progress with xargs
I'm using xargs to execute a command on a set of input parameters something like this:
cat <someinput> | xargs -n 1 -P 5 <somecmd>
The input file is really long and take a long time to run. So I'm just waiting for the command prompt to show up. Is there a way to display a progress bar for the number of input arguments that have completed?
I tried using 'bar' but I always got an 'infinite' throughput. It seems like xargs reads the entire input before executing commands.
If you have GNU Parallel you can run:
cat <someinput> | parallel --bar -P 5 <somecmd>
GNU Parallel is a general parallelizer and makes is easy to run jobs in parallel on the same machine or on multiple machines you have ssh access to.
If you have 32 different jobs you want to run on 4 CPUs, a straight forward way to parallelize is to run 8 jobs on each CPU:
GNU Parallel instead spawns a new process when one finishes - keeping the CPUs active and thus saving time:
Installation
A personal installation does not require root access. It can be done in 10 seconds by doing this:
(wget -O - pi.dk/3 || curl pi.dk/3/ || fetch -o - http://pi.dk/3) | bash
For other installation options see http://git.savannah.gnu.org/cgit/parallel.git/tree/README
Learn more
See more examples: http://www.gnu.org/software/parallel/man.html
Watch the intro videos: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1
Walk through the tutorial: http://www.gnu.org/software/parallel/parallel_tutorial.html
Sign up for the email list to get support: https://lists.gnu.org/mailman/listinfo/parallel
You can use pv :
cat <someinput> | pv -p -s sizeof_someimput | xargs -n 1 -P 5 <somecmd>
With this you will know where the reading of someimput is, so you will know approximately where the treatment of someimput is.
If you're looking for just a general indication of progress the simplest method is to just echo prior to doing the command you'd like to do.
Example:
cat <someinput> | xargs -I{} sh -c 'echo {}; <somecmd>;'
-I{}
sets {}
to the current string being processed
sh -c
will allow you to execute multiple commands (note: semi-colon after every command is required including the last one.