LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Verifying a program is running by cron job, if not starting it. (https://www.linuxquestions.org/questions/linux-general-1/verifying-a-program-is-running-by-cron-job-if-not-starting-it-438668/)

AsstInterests 04-25-2006 09:54 AM

Verifying a program is running by cron job, if not starting it.
 
Like the title says I have a program that I want to make sure is running 24/7. Every hour I want to "check" if it is running using a cron job, and if so then nothing, but if it isn't then I want to start it. Currently I have it setup using this command:

/home/username/public_html/loca/locb/sc_trans_linux

and you can of course guess the problem... I had 20 processes of the same thing running in no time :) So how can I do it so it only starts an instance if there isn't one running already ?

--------
AsstInterests

WIPR : nyc01.egihosting.com:6336

acid_kewpie 04-25-2006 10:10 AM

Code:

[ "$(/sbin/pidof myprocessname)" ] || command_if_not_running.sh

Emerson 04-25-2006 10:12 AM

Another option is to start your process from inittab with respawn action.

AsstInterests 04-25-2006 12:26 PM

Quote:

Originally Posted by acid_kewpie
Code:

[ "$(/sbin/pidof myprocessname)" ] || command_if_not_running.sh

Ok... tried that :
Code:

[ "$(/sbin/337)" ] || /home/username/public_html/loca/sc_trans_linux
and I keep getting the following error :

/bin/sh: /sbih/337: Not a directory

AsstInterests 04-25-2006 12:27 PM

Quote:

Originally Posted by Emerson
Another option is to start your process from inittab with respawn action.

I don't have an inittab, I am running this from a webbased control panel.

acid_kewpie 04-25-2006 12:27 PM

pidof is a real program, the point is to get all pids for the named process, which is it is not running, will be null.

AsstInterests 04-25-2006 12:54 PM

Quote:

Originally Posted by acid_kewpie
pidof is a real program, the point is to get all pids for the named process, which is it is not running, will be null.

Damn simplicity has always gotten me.. I think that might have fixed my problem. Thanks !

AsstInterests 04-25-2006 02:28 PM

Hmmm keeps creating a new process. So I end up with 2 or more processes.

acid_kewpie 04-25-2006 02:48 PM

i'd have to assume a typo... check that this has the same effect for you:
Code:

[root@kermit ~]# [ "$(/sbin/pidof bash)" ] || echo BASH IS NOT RUNNING!
[root@kermit ~]# [ "$(/sbin/pidof bashxxx)" ] || echo BASHXXX IS NOT RUNNING!
BASHXXX IS NOT RUNNING!

so a process that clearly does exist is found, so the echo is not executed. when a fictious program is requested and not found, the echo command fires. you may well have whitespace issues or such like.


All times are GMT -5. The time now is 06:51 PM.