LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   How to control execution of programs in a shell script. (http://www.linuxquestions.org/questions/programming-9/how-to-control-execution-of-programs-in-a-shell-script-804430/)

Chrisantha1 04-27-2010 12:22 AM

How to control execution of programs in a shell script.
 
Dear LinuxQuestions,

Do you know how to write a shell script that executes say 4 instances of the same program in different directories at the same time, and once ONE instance completes it executes a new instance of that program in a new directory, and so on, until 100 instances have been executed, each in their own directory.


Cheers,
Chrisantha

grail 04-27-2010 12:49 AM

Maybe if you gave us an example we may be able to assist?

Chrisantha1 04-27-2010 01:07 AM

I'm basically wanting to run several versions of a C++ genetic algorithm in Mac OS X. I want to run a batch of these programs on a server that has 5 nodes, and I want to start a new program each time one of the previous programs ends.

It seems this must consist of 3 parts.

1. Regular checking to see if a program has ended
2. Starting a program conditional upon this.
3. Making sure it starts in its own directory.

Basically, I have not done any sophisticated shell programming before.

Cheers,
Chrisantha

ntubski 04-27-2010 10:15 AM

Quote:

Basically, I have not done any sophisticated shell programming before.
Sophisticated shell programming is a bad idea.

Code:

#!/bin/sh
seq --format 'dirname%g' 100 | xargs --max-args=1 --max-procs=4 ./gene.sh

gene.sh:
Code:

#!/bin/sh

DIR="$1"

mkdir "$DIR"
cd "$DIR" || exit 1

/path/to/your/program


bigearsbilly 04-28-2010 02:45 AM

Quote:

Originally Posted by ntubski (Post 3949410)
Sophisticated shell programming is a bad idea.


never a truer word spoken.
they can be horrendous.

Chrisantha1 04-28-2010 03:29 AM

Thanks
 
Thank you I shall examine this and learn.

Chrisantha


All times are GMT -5. The time now is 06:55 AM.