LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   start applications with shell script (https://www.linuxquestions.org/questions/linux-newbie-8/start-applications-with-shell-script-781739/)

ufmale 01-12-2010 12:29 PM

start applications with shell script
 
I am trying to start multiple application with a shell script,but have no idea how to do it.
Basically, i want to start the same application in different directories, say consumer1/app, consumer2/app, consumer3/app

I was thinking about writing a script like:

-------------------
cp app consumer1/
execute consumer1/app
cp app consumer2/
execute consumer2/app
.
.
.
-------------------

My problem is that I don't know how to execute to app
(execute consumer2/app) in such a way that the script can continue.

Does anyknow have a solution for me?

David1357 01-12-2010 12:51 PM

Quote:

Originally Posted by ufmale (Post 3823960)
My problem is that I don't know how to execute to app (execute consumer2/app) in such a way that the script can continue.

Use syntax like this
Code:

consumer2/app >> /dev/null 2>&1 &
  or
nohup consumer2/app >> /dev/null 2>&1 &

The first will start the application in the background with all output redirected to "/dev/null". The second will disconnect the application from the terminal so it will not die when you exit your shell.

anand.arumug 01-13-2010 08:23 AM

Quote:

Originally Posted by David1357 (Post 3824001)
Use syntax like this
Code:

consumer2/app >> /dev/null 2>&1 &
  or
nohup consumer2/app >> /dev/null 2>&1 &

The first will start the application in the background with all output redirected to "/dev/null". The second will disconnect the application from the terminal so it will not die when you exit your shell.

the program you use to copy the application "cp" is invoked in the script just by its name, so wont the application you want to execute in different directories will also execute by just calling them by their executable name? or am i missing something? That is,

Code:

cp app ./dir1
app&

cp app ./dir1
app&

...

I guess you might want to be "nice" before you start all the programs so that everything runs with equal amount of cpu time.

chrism01 01-13-2010 06:13 PM

The prog will be called by searching your $PATH, unless you specify a relative or absolute path.
Running a prog in different dirs can mean 1 of several things

1. run the (one version) of the prog and pass the dir to use as a cmd line param, if it accepts that method.
2. have a separate copy of the prog in each desired dir and cd into that dir and call it with ./prog
3. cd into the desired dir and call the prog via $PATH
4. cd into the desired dir and call the prog using an absolute path
5. cd into the desired dir and call the prog using a relative path


Incidentally, it's

prog &

not

prog&

to background a prog; note the space there.
To avoid the prog terminating when you logout, add nohup thus

nohup prog &

HTH


All times are GMT -5. The time now is 02:08 PM.