Running same script multiple times concurrently...

Hi,

I was hoping someone would be able to help me out. I've got a Python script that I need to run 60 times concurrently (with the number added as an argument each time) via nightly cron. I figured that this would work:

30 1 * * * for i in $(seq 0 59); do [script] $i \&; done

However, it seems to run it 60 times in sequence (waiting for each script instance to finish), instead of sending each one to the background and moving on through all 60.

Anybody have any ideas on how I can get this to work as intended? What am I doing wrong? Any help would be appreciated.

Thanks,
Cedric

Put all your complex logic into a separate script and then call that single script from cron.

It will greatly simplify your testing.

Porter,

Whether I call a script or execute the loop directly in cron, my problem remains the same: How do I call the same script 60 times to run concurrently. I really don't want this loop in my script, as I'm interested in having each script instance actually end when it is done. (Each instance is running against a different machine and will vary greatly in execution time.) To simplify, this is what I was trying to do:

for i in $(seq 0 59); do [script] $i \&; done

But it seems to go in sequence rather than pushing each instance into the background and moving on through the others. Any ideas?

Thanks for your help.

Cedric

#!/bin/sh

for i in whatever...
do
         yourscript $i  &
done
wait

What porter is trying to tell you is: the problem with your cron job is problably the escaped ampersand ("&"). Once you do not escape it (that is: precede it with a backslash) it becomes a command for the shell to put the process in background. The way you wrote it the escaped ampersand will probably be passed to your script as parameter. You could try to find out if this is the case by displaying "$2" inside your script.

bakunin