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 acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet java laptop malware memory monitor motherboard music network obp printer problem ram registry repair router slow software sound toshiba trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
if process running....

Reply  
Thread Tools
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
20-Dec-2005, 03: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, 03: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
Member with 205 posts.
 
Join Date: Aug 2003
20-Dec-2005, 03: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
Member with 205 posts.
 
Join Date: Aug 2003
20-Dec-2005, 04:01 PM #4
im defining user earlier in the program
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
20-Dec-2005, 04:09 PM #5
i am pretty sure we have covered this is exact problem a while back in the linux forum.
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
20-Dec-2005, 04: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
Member with 205 posts.
 
Join Date: Aug 2003
20-Dec-2005, 04: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
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
20-Dec-2005, 04: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...
$
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
20-Dec-2005, 04: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
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
20-Dec-2005, 05:00 PM #10
Do a search for posts by surfnschultz in the Unix/Linux forum.
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
20-Dec-2005, 05: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.
Reply

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.

Search Tech Support Guy

Find the solution to your
computer problem!




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



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:48 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.