开发者

Bash script for looping through a program for several different input files

I 开发者_运维技巧would like a bash script to run a program (taking several variables and an input file) in the background, but I want the script to only process one input file (all input files in one directory) at a time. e.g.

#!/bin/sh  
for file in *  
do  
    ~/FrameDP/bin/FrameDP.pl --cfg ~/FrameDP/cfg/FrameDP.cfg --no_train --infile /home/bop08olp/FrameDP/data/"$file" --outdir ~/FrameDP/test  
done

I'm guessing the above script is not going to wait between each processing of separate input files, but will just start them all at once. The program generates lots of child processes. Any pointers appreciated. Thanks!


sh loops are not parallelized, you can verify it by running :

for i in *
    sleep 1
done

And you'll see that if you have > 1 file that the total time is > than 1s but equal to 'number of files' seconds.

So if actually running the code snippet you gave ran all the process in the same time, it's because of your perl script have a feature to run in the background, you should review your perl script, not your shell script.


Maybe I am thinking too simple and I am too late, but what about

find . -depth 1 -exec ~/FrameDP/bin/FrameDP.pl --cfg ~/FrameDP/cfg/FrameDP.cfg --no_train --infile /home/bop08olp/FrameDP/data/{} --outdir ~/FrameDP/test \; &

where {} takes the place of the former variable $file and "\;" is find's demanded sequence to denote the end of the exec clause?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜