0

I have a shell script that is sending in about 150 files to a python program I wrote. I have no idea how long it is going to take, so I was wondering if there was a terminal command to either:

a) tell me which file is currently being worked on

b) how many files are left to run

Here's my shell:

#!/bin/bash

ls fp00t*g*k2odfnew.dat | while read line; do
    echo $line
    python file_editor.py $line 
done 
artdanil
  • 4,952
  • 2
  • 32
  • 49
  • is there a command to display how many total files? (quick google search...: `ls -1 | wc -l` ) if there is, then just take that command, and after each iteration, subtract 1 from that number, and then display the number. – TehTris May 23 '13 at 16:50
  • Do you want to handle the progress in the shell or python? For displaying progress in Python you can read [Python Progress Bar](http://stackoverflow.com/q/3160699/214178) question. By the way, `$line` is a bit misleading, since it refers to file which you are planning to edit. – artdanil May 23 '13 at 16:51
  • @TehTris Do I subtract from that number in the shell with some loop? I have been using unix for 2 weeks, and shell scripts for 1, so I do not know how to interpret such a vague response. Thanks though! – hey mordecai May 23 '13 at 16:58
  • @artdanil I do not wish to add any more lines to the python script itself. I figured that after I type ./file_editor.sh that there would be a command to say which file is currently running. – hey mordecai May 23 '13 at 16:59

1 Answers1

2

PipeViewer will probably do what you need: http://www.catonmat.net/blog/unix-utilities-pipe-viewer/

Something like this might work, putting both ls and pv in line mode:

#!/bin/bash

ls -1 fp00t*g*k2odfnew.dat | pv -l | while read line; do
    echo $line
    python file_editor.py $line 
done

you can also supply a total to pv so it knows how many you're counting up to, so the progress bar works properly:

#!/bin/bash

ls -1 fp00t*g*k2odfnew.dat | pv -l -s`ls -1 fp00t*g*k2odfnew.dat | wc -l` | while read line; do
    echo $line
    python file_editor.py $line 
done

Full pv docs here: http://www.ivarch.com/programs/quickref/pv.shtml

Duncan Lock
  • 12,351
  • 5
  • 40
  • 47