Printable Version of Topic

Click here to view this topic in its original format

Linuxhelp _ Programming in Linux _ Spawn Process

Posted by: demanaz Nov 28 2008, 03:41 PM

Hi all:

I'm writing a korn shell script that runs on one box and connects to multiple (100+) boxes:

################ SCRIPT: ########################
#!/bin/ksh

for srv in `cat server_list|grep -v '#'`
do
echo "starting $srv"
ssh $srv "./extract_script"
scp $srv:/scripts/extract_script_output extract_script_output_$srv
echo "finished $srv"
done

################ SCRIPT: ########################

(the actual script does a lot more, but this is the basic idea)

Is it possible in ksh to spawn the for loop statements into other processes so i can be running the commands on all the servers at the same time w/o having to wait for each server to finish?

I could schedule the extract_script to run on each server individually, but then i have to maintain 100+ versions/schedules. This would be the easiest way for maintaince...

thx in advance

Posted by: docmur Dec 2 2008, 06:59 AM

Sure you can just take a look at forking the process using fork() and that pass the execution of the process using execvp() then korn will spawn a new instance of a shell for each process so you don't have to wait for one to finish first.

Thanks

Docmur

Posted by: demanaz Dec 4 2008, 10:15 AM

QUOTE (docmur @ Dec 2 2008, 05:59 AM) *
Sure you can just take a look at forking the process using fork() and that pass the execution of the process using execvp() then korn will spawn a new instance of a shell for each process so you don't have to wait for one to finish first.

Thanks

Docmur



I had researched forking and it sounded kind of dangerous in that processes could get spawned out of control. i wasnt sure if there was a safer way to do this. do you have any guides on forking you recommend?

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)