Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Linux and Unix
Tag Cloud
access audio black screen blue screen boot bsod connection crash dell desktop driver drivers dvd email error excel firefox hard drive hardware hijackthis internet keyboard laptop malware monitor network networking outlook problem processor recovery registry cleaner router safe mode screen slow sound spyware trojan upgrade vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
if process running....

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
cgjoker's Avatar
Senior Member with 205 posts.
 
Join Date: Aug 2003
20-Dec-2005, 02:32 PM #1
if process running....
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's Avatar
Senior Member with 1,246 posts.
 
Join Date: Sep 2003
Experience: Linux~su
20-Dec-2005, 02:54 PM #2
well first things first..where do you define user? Also the grep Process, will only return the current running grep for Process...
cgjoker's Avatar
Senior Member with 205 posts.
 
Join Date: Aug 2003
20-Dec-2005, 02:59 PM #3
problem
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's Avatar
Senior Member with 205 posts.
 
Join Date: Aug 2003
20-Dec-2005, 03:01 PM #4
im defining user earlier in the program
Squashman's Avatar
Distinguished Member with 14,988 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
20-Dec-2005, 03:09 PM #5
i am pretty sure we have covered this is exact problem a while back in the linux forum.
cgjoker's Avatar
Senior Member with 205 posts.
 
Join Date: Aug 2003
20-Dec-2005, 03:32 PM #6
i checked out my previous posts... couldn't find this there... can you direct to where? ill check out all posts in linux.
cgjoker's Avatar
Senior Member with 205 posts.
 
Join Date: Aug 2003
20-Dec-2005, 03:44 PM #7
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's Avatar
Distinguished Member with 14,988 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
20-Dec-2005, 03:56 PM #8
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...
$
__________________
I hate asking the same question twice!
How to ask questions the smart way!
Microsoft MVP - User Desktop Experience
cgjoker's Avatar
Senior Member with 205 posts.
 
Join Date: Aug 2003
20-Dec-2005, 03:59 PM #9
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's Avatar
Distinguished Member with 14,988 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
20-Dec-2005, 04:00 PM #10
Do a search for posts by surfnschultz in the Unix/Linux forum.
cgjoker's Avatar
Senior Member with 205 posts.
 
Join Date: Aug 2003
20-Dec-2005, 04:09 PM #11
couldn't find anything under his id that would explain the issue im having with my looping while ps'ing on a process.
Closed Thread Bookmark and Share

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 07:55 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.