LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-07-2011, 01:38 PM   #1
3lixy
LQ Newbie
 
Registered: Aug 2011
Posts: 2

Rep: Reputation: Disabled
Shell script to start program if not running


Hey guys,

I found this thread http://www.linuxquestions.org/questi...unning-625589/ but the code is a bit beyond me.

I am looking for assistance in creating a script that does the following (written in the style of PHP):

If (program A is running and program B is running) {
do nothing
}
elseif (program A is not running and program B is runnning) {
term program B
start program A
sleep 120
start program B
}
elseif (program A is running and program B is not running) {
start program B
}

I intend to run the script via crontab every hour.

The reason for the script is because program a tends to crash randomly (it terms itself) and program b is an interface to program A. When program A dies program B has to be restarted when program A is back running.

i am using Ubuntu 10.04 LTS.

Thanks for your help.

Last edited by 3lixy; 08-07-2011 at 01:40 PM. Reason: added distro
 
Old 08-07-2011, 01:51 PM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hello and Welcome to LinuxQuestions,

You'll have a hard time finding someone here at LQ that will do all the work for you. You will learn a lot more if you try to write a shell script yourself and calling in our help if you cannot get it to work or are getting errors you cannot solve. To start you could read about Bash scripting at the following links:
Bash Guide for Beginners
Advanced Bash Scripting Guide

Basically, show us what you've got already and tell us where you have doubts or where it's failing and we'll help you out for sure.

Looking forward to your participation in the forums. Have fun with Linux.

Kind regards,

Eric
 
Old 08-07-2011, 01:58 PM   #3
3lixy
LQ Newbie
 
Registered: Aug 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks Eric. A good starting place. I think I should be able to use my existing programming knowledge to make a good go at it .
 
Old 08-07-2011, 02:01 PM   #4
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Quote:
Originally Posted by 3lixy View Post
Thanks Eric. A good starting place. I think I should be able to use my existing programming knowledge to make a good go at it .
Hello,

That's the spirit! Don't hesitate to post any questions or doubts here at LQ. Have fun with Linux.

Kind regards,

Eric
 
Old 08-07-2011, 03:22 PM   #5
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
This is "ola" script
Code:
#!/bin/bash

foo=""; bar=""
pgrep $1 > /dev/null ; foo=$?
pgrep $2 > /dev/null ; bar=$?

if [ $foo = "0" ] ; then
    if [ $bar = "1" ] ; then
          $2 &
           exit 0
    fi ;
else if [ $bar = "0" ] ; then
    pkill $2
    $1 &
    sleep
    $2 & 
   exit 0
    fi ;
fi ;
The command is
Code:
 
$ ola A B
Of course use on its own risk. Test first.
 
  


Reply



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 to start another program, if not running. cooljai Linux - Software 13 03-13-2012 04:39 AM
running a shell script which invokes another shell program!!! raghu123 Programming 1 08-04-2008 09:10 AM
running a C program from shell script jkeertir Linux - Newbie 3 05-19-2008 05:05 AM
Running shell script within a C or C++ program Quantum0726 Programming 2 06-15-2005 09:14 PM
running a program from shell script Suinatsa Programming 10 04-14-2005 11:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:30 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
Open Source Consulting | Domain Registration