View the Most Wanted LQ Wiki articles.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

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


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 10:25 AM. Reason: script program runnig
Old 12-13-2006, 10:49 AM   #2
Registered: Mar 2003
Location: North Carolina
Distribution: Gentoo
Posts: 168

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

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, 10:53 AM   #3
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307

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

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


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 11:24 PM
How can I check to see if a script is running? slick_willie Programming 13 03-16-2007 11:18 AM
need help to write script to check the process health and automatically restart it dragondad Programming 3 11-01-2006 01:23 PM
Check if program is running Conjurer Programming 8 11-17-2005 02:37 PM
program to check to make sure a process is running? IceNineJon Linux - Software 7 08-06-2003 03:07 PM

All times are GMT -5. The time now is 05:14 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration