I have a small script that loops through all files of a folder and executes a (usually long lasting) command. Basically it's
for file in ./folder/*;
do
./bin/myProgram $file > ./done/$file
done
(Please Ignore syntax errors, it's just pseudo code).
I now wanted to run this script twice at the same time. Obviously, the execution is unnecessary if ./done/$file exists. So I changed the script to
for file in ./folder/*;
do
[ -f ./done/$file ] || ./bin/myProgram $file >./done/$file
done
So basically the question is:
Is it possible that both scripts (or in general more than one script) actually are at the same point and check for the existance of the done
file which fails and the command runs twice?
it would be just perfect, but I highly doubt it. This would be too easy :D If it can happen that they process the same file, is it possible to somehow "synchronize" the scripts?
xargs
with the-P
option available, see this question. – jw013 May 10 '12 at 08:58done/$file
markers seem a little likemake
targets to me. – sr_ May 10 '12 at 09:11xargs
or GNUmake
or some version ofparallel
, then there is no need to reinvent this particular wheel. – jw013 May 10 '12 at 09:20