LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to write script with check running program (https://www.linuxquestions.org/questions/programming-9/how-to-write-script-with-check-running-program-510042/)

VooZ2_uk 12-13-2006 09:25 AM

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.

asommer 12-13-2006 09:49 AM

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.

nx5000 12-13-2006 09:53 AM

Code:

pgrep program || program
you can replace pgrep by pidof if you don't have it

asommer 12-13-2006 09:57 AM

pgrep!! Genius I never new about that command. Thanks!


All times are GMT -5. The time now is 03:13 AM.