LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-25-2006, 09:54 AM   #1
AsstInterests
LQ Newbie
 
Registered: Apr 2006
Posts: 5

Rep: Reputation: 0
Question 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
 
Old 04-25-2006, 10:10 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Code:
[ "$(/sbin/pidof myprocessname)" ] || command_if_not_running.sh
 
Old 04-25-2006, 10:12 AM   #3
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 6,317

Rep: Reputation: Disabled
Another option is to start your process from inittab with respawn action.
 
Old 04-25-2006, 12:26 PM   #4
AsstInterests
LQ Newbie
 
Registered: Apr 2006
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
Old 04-25-2006, 12:27 PM   #5
AsstInterests
LQ Newbie
 
Registered: Apr 2006
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
Old 04-25-2006, 12:27 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
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.
 
Old 04-25-2006, 12:54 PM   #7
AsstInterests
LQ Newbie
 
Registered: Apr 2006
Posts: 5

Original Poster
Rep: Reputation: 0
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 !
 
Old 04-25-2006, 02:28 PM   #8
AsstInterests
LQ Newbie
 
Registered: Apr 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Hmmm keeps creating a new process. So I end up with 2 or more processes.
 
Old 04-25-2006, 02:48 PM   #9
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
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.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cron backup job not running dsschanze Linux - General 9 07-29-2005 08:47 PM
script not running as a cron job sanjith11 Programming 5 11-23-2004 08:42 AM
cron job not running vincebs Linux - Software 34 10-30-2004 01:27 PM
Cron job not running? james_cwy Linux - Newbie 6 12-14-2003 08:24 PM
Cron Job Not Running pzorn Linux - General 4 10-02-2003 01:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration