Results 1 to 2 of 2
Im using an open embeded distro and a device that used a very slimmed down linux so i need to check if a process is running on it and lots ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-17-2011 #1Just Joined!
- Join Date
- Apr 2009
- Posts
- 18
Grep & process question
Im using an open embeded distro and a device that used a very slimmed down linux so i need to check if a process is running on it and lots of examples wont work on the net because of the lack of tools in the distro
so I wrote a script
The script runs fine, but I always receive the script is not running message so the test of the process is incorrect.Code:#!/bin/sh my_string="telnetd" echo "my script is running" if [ `ps -ef | grep $my_string | grep -v grep` ]; then { echo "$my_string is already running" } else { echo "$my_string is not running - restarting" cd / /bin/sh /usr/script/myscript.sh start } fi
even if I put in a not test !:
if [ `! ps -ef | grep $my_string | grep -v grep` ]; then
Can anyone tell me what i am doing wrong?
- 02-17-2011 #2Just Joined!
- Join Date
- Apr 2009
- Posts
- 18
I think this is right
if [ ! $? ` ps -ef | grep $my_string | grep -v grep` -eq 0 ]; then
Can anyone confirm whether this would work for me?
Thanks in advance
Code:#!/bin/sh my_string="telnetd" echo "my script is running" if [ ! $? ` ps -ef | grep $my_string | grep -v grep` -eq 0 ]; then { echo "$my_string is already running" } else { echo "$my_string is not running - restarting" cd / /bin/sh /usr/script/myscript.sh start } fi


Reply With Quote
