# if process running....



## cgjoker (Aug 13, 2003)

hey there... im trying to test if a process is running and if it is then do something.... here is what i have so far but its not working?

test_process=`ps -ef | grep ${user} | grep Process`

if ${test_process} 
then
process_ shutdown >> $LOG 2>&1
if (($1 >= 1))
then
write_output "RETURN CODE 7 : $1"
exit
else 
write_output "RETURN CODE 0 : $1"
fi
else
echo "RETURN CODE:6: service already stopped"
fi


----------



## tsunam (Sep 14, 2003)

well first things first..where do you define user? Also the grep Process, will only return the current running grep for Process...


----------



## cgjoker (Aug 13, 2003)

the problem im encountering is that i think that the grep command is returning a positive value thereby causing this to continually loop.

c


----------



## cgjoker (Aug 13, 2003)

im defining user earlier in the program


----------



## Squashman (Apr 4, 2003)

i am pretty sure we have covered this is exact problem a while back in the linux forum.


----------



## cgjoker (Aug 13, 2003)

i checked out my previous posts... couldn't find this there... can you direct to where? ill check out all posts in linux.


----------



## cgjoker (Aug 13, 2003)

heres another crack at it, but its looping repeatedly for some reason

for test_service in `ps -ef | grep me | grep service`
do
if [ $test_service ]
then
echo "Shutting down service"
stop service
if (($1 >= 1))
then
write_output "RETURN CODE 7 : $1 : ERROR"
exit
else
echo "RETURN CODE: 0: $1 : SUCCESSFULL"
sleep 10
else
write_output " service already stopped"
fi

fi
done


----------



## Squashman (Apr 4, 2003)

You want to test if a Service is running or not. That is easy on most linux distributions. I don't know what you are running but on most linux distro's you can just do this.

/etc/init.d/./servicename status

$ ./httpd status
httpd (pid 24981 24980 24979 24978 24977 24976 24975 24974 24971) is running...
$


----------



## cgjoker (Aug 13, 2003)

its actually unix im using... and i can check if the process is running, but i want to action something if it is... i would also like to output and error code of 7 if the stop service command doesn't work, code 0 if it does.

with this code im using its causing it to loop for some reason.


----------



## Squashman (Apr 4, 2003)

Do a search for posts by surfnschultz in the Unix/Linux forum.


----------



## cgjoker (Aug 13, 2003)

couldn't find anything under his id that would explain the issue im having with my looping while ps'ing on a process.


----------

