LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-13-2006, 09:25 AM   #1
VooZ2_uk
LQ Newbie
 
Registered: Dec 2006
Posts: 1

Rep: Reputation: 0
Question How to write script with check running program


Hi,

I need to write script witch will check is program running or not, and if not then start to program. I know how do to check if program run, but don't know how to do that script start a program if it's not running.

Last edited by VooZ2_uk; 12-13-2006 at 09:25 AM. Reason: script program runnig
 
Old 12-13-2006, 09:49 AM   #2
asommer
Member
 
Registered: Mar 2003
Location: North Carolina
Distribution: Gentoo
Posts: 168

Rep: Reputation: 30
if [ `ps -ef | grep -o $Program_name` ]
then
/etc/init.d/$Program_name start #or however you start the program
fi


You may have to tweak the grep part. grep -o just returns whatever was matched. You could also adjust the ps -ef part. Maybe use a ps -A then grep the output.
 
Old 12-13-2006, 09:53 AM   #3
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 52
Code:
pgrep program || program
you can replace pgrep by pidof if you don't have it
 
Old 12-13-2006, 09:57 AM   #4
asommer
Member
 
Registered: Mar 2003
Location: North Carolina
Distribution: Gentoo
Posts: 168

Rep: Reputation: 30
pgrep!! Genius I never new about that command. Thanks!
 
  


Reply

Tags
program, script


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: Check if a program is running naimslim89 Programming 12 05-08-2012 10:24 PM
How can I check to see if a script is running? slick_willie Programming 13 03-16-2007 10:18 AM
need help to write script to check the process health and automatically restart it dragondad Programming 3 11-01-2006 12:23 PM
Check if program is running Conjurer Programming 8 11-17-2005 01:37 PM
program to check to make sure a process is running? IceNineJon Linux - Software 7 08-06-2003 02:07 PM


All times are GMT -5. The time now is 02:11 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