LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-27-2010, 01:22 AM   #1
Chrisantha1
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Rep: Reputation: 0
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
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 04-27-2010, 01:49 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,689

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
Maybe if you gave us an example we may be able to assist?
 
Old 04-27-2010, 02:07 AM   #3
Chrisantha1
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Original Poster
Rep: Reputation: 0
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
 
Old 04-27-2010, 11:15 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,541

Rep: Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878
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
 
2 members found this post helpful.
Old 04-28-2010, 03:45 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,312

Rep: Reputation: 175Reputation: 175
Quote:
Originally Posted by ntubski View Post
Sophisticated shell programming is a bad idea.

never a truer word spoken.
they can be horrendous.
 
Old 04-28-2010, 04:29 AM   #6
Chrisantha1
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks

Thank you I shall examine this and learn.

Chrisantha
 
  


Reply

Tags
files, multiple, running, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script execution on double click havejeet Linux - Newbie 6 06-05-2010 04:08 AM
LXer: Parallel SSH execution and a single shell to control them all LXer Syndicated Linux News 0 10-30-2008 02:20 PM
! HELP ! Script : How to control parent shell ??? fawqati Programming 1 06-03-2006 01:58 PM
Speeding up Shell Script execution?? funkymunky Programming 8 07-16-2004 09:39 PM
Shell Script to control logins NIkss Programming 9 12-17-2003 01:53 PM


All times are GMT -5. The time now is 09:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration