LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 07-02-2009, 02:35 PM   #1
j_65_uk
LQ Newbie
 
Registered: Jul 2009
Posts: 2

Rep: Reputation: 0
Executing multiple instances of a binary file from a single script?


Hi guys,



I'm a Linux newbie and I've been using Debian 4.0 for a few months now, trying different things and getting to grasps with the basics.



My question is about ways of executing a binary (.bin) file from a script.



I've setup a gameserver for FEAR Combat. After copying the files into the home directory for the 'fear' user I created for the purpose, you then execute a script called start.sh which links to a library file then execute the game binary file (fearserver.bin).


This is the start.sh script



#!/bin/sh
export LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH
./fearserver.bin


This all works fine, but then I tried to take things further and run 3 separate instances of the server on 3 separate ports.



I first tried calling/executing the binary 3 times in a row in the script, however what happens is that the first instance loads and runs and the script pauses there until you terminate the instance, and then the second instance is executed and so on...


#!/bin/sh
export LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH
./fearserver.bin
./fearserver.bin
./fearserver.bin



My workaround (which does actually work) so far has been to create a separate start.sh script for each of the instances I'm trying to create, then I open up a remote console session to the Debian machine using Putty/SSH on Windows XP, login as the fear user I created, execute the script for the first instance of the binary, then close the session window without logging out. The .bin continues to run on the system. I then repeat this twice more and end up with the desired 3 instances of the binary all running AT THE SAME TIME under the fear user account.



So my question is can I get the same result launching the instances from the same script from a single session, rather than having to open a separate session to launch each instance?

Any help much appreciated!



Thanks
 
Old 07-02-2009, 03:15 PM   #2
tredegar
Guru
 
Registered: May 2003
Location: London, UK
Distribution: Ubuntu 10.04, mostly
Posts: 6,007

Rep: Reputation: 366Reputation: 366Reputation: 366Reputation: 366
I know nothing about fearserver but have you tried "putting in the background"?

With bash you can run a command "in the background", and not wait for it to complete / finish and terminate before you get the prompt back. So you can issue another command straight away. The process running "in the background" just carries on, but gives you your shell prompt back. Errors are generally reported back to the shell you are in, unless you redirect them.

You can do this by appending & to the command. Like this:
Code:
./fearserver.bin &
It's worth a try.

See man bash for the full story.

And Welcome to LQ!.
 
Old 07-02-2009, 03:35 PM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,269

Rep: Reputation: 165Reputation: 165
why multiples?
a good server should handle spawning instances itself usually.
do they not all try to bind the same port?
usually a service will have a startup script which you can activate on boot.

also the servers may die if you call them from an interactive
script and you close the window.

have you checked the docs to see if the server can daemonize properly?

FYI look at:

man at
man nohup
 
Old 07-02-2009, 04:56 PM   #4
j_65_uk
LQ Newbie
 
Registered: Jul 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Smile

Hi guys,

Tredegar - Adding the 'run in background' did the trick! That's exactly what I was after - useful technique to know and a nice simple answer

I've now created a single script that does everything.

Interestingly it does dump the 'initial' text output of each instance to the console, but this time all at once. There is no 'prompt' visible afterwards on the console, but as soon as I start typing it accepts it as a new command and the server instances disapear into the background. Just a quirk though, doesn't interfere with anything.

Bigearsbilly - The fearserver by default runs on port 27888. To change any of the settings (including the port) you have to specify an optionsfile when executing the file. I didn't mention this previously as it wasn't really relevant.

So my 'combined' startup script looks like this:

#!/bin/sh
export LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH
./fearserver.bin -optionsfile /home/fear/FEAR/ServerOptions/ServerOptions-SMTDM $
./fearserver.bin -optionsfile /home/fear/FEAR/ServerOptions/ServerOptions-SMDM $
./fearserver.bin -optionsfile /home/fear/FEAR/ServerOptions/ServerOptions-SMCTF $

Having 3 instances lets me have the option of 3 different game modes. I could make the script run at startup but would prefer to start the servers manually...

I can confirm the 3 instances laucnhed from the single script are all running smoothly and are being thoroughly tested

Thanks for all your help guys!
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script iterating multiple instances of java GUI on different desktops rockdiablo Linux - Desktop 2 06-23-2009 07:35 AM
Storing multiple options in a single variable (binary addition?) matt_heys Programming 1 04-03-2009 03:38 PM
Preventing multiple instances of a shell script from running concurrently Dave Lerner Programming 12 01-03-2007 09:27 PM
executing a script in multiple subdirectories jerryfreak Linux - Newbie 1 04-19-2005 08:34 PM
Difficulty executing a binary file Judland Linux - Software 2 10-03-2003 11:03 PM


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

Main Menu
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