grep for a certain process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep for a certain process
# 1  
Old 11-23-2010
grep for a certain process

Hey all,

I got some help last week and It will temporarily work

We have a certain process that runs several processes within it. Here is an example:

Code:
 
   Date      -  0:04 process1-database: db (state) 
   Date      -  0:04 process1-database: db (state) 
   Date      -  0:04 process1-database: db (state) 
   Date      -  0:00 process1-database: (state2)

The code I was given to grep for this is the following:

Code:
 
ps -ef | grep state2

That will work, and should be good forever, but we are worried about another process coming up that might also have state2 in it.

Are there any alternatives to doing this?
# 2  
Old 11-23-2010
How does the output look if you have more processes with state2 and what should be the output?
# 3  
Old 11-23-2010
Hi Franklin,

My concern is that if I grep state2 and perhaps another application running on the box that is completely unrelated to the system that we are using returns "state2" after a grep, it could cause issues.
# 4  
Old 11-23-2010
Yes we know what is your concern, but we have to know how exactly the output looks like, so we can try to identify unique pattern, grepping of which could solve your issue.
# 5  
Old 11-23-2010
lets say I issue this command..

Code:
 
ps -ef | grep state2

and this is returned

Code:
 
Date      -  0:04 process1-database: db (state2) 
Date      -  0:00 process2-database: db (state2)

I'd need to narrow it down to grepping for process1 (state2)

I apologize if I am explaining this badly, I am still new to unix and scripting...I'm learning though Smilie
# 6  
Old 11-23-2010
You can do something like:
Code:
ps -ef | grep 'process1.*(state2)'

This User Gave Thanks to Franklin52 For This Post:
# 7  
Old 11-23-2010
Yet again you guys come through, thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can't grep name of process

Hi I am trying to grep the name of the user running a specific process on one of my systems.$ ps -efl | grep 'Introscope_WebView.lax' | grep -v grep| awk '{print $3}' $ ps -efl | grep 'Introscope_WebView.lax' 0 S apm 14572 17108 0 80 0 - 28164 pipe_w 10:31 pts/4 00:00:00 grep... (2 Replies)
Discussion started by: simpsa27
2 Replies

2. Shell Programming and Scripting

Unable to grep the process

I have user1 run a script called logginexpert.sh while has this line of code sleep 888I then login to another putty session with another user2 and try to grep for the logginexpert.sh process using ps -ef | grep exSunOS mymac 5.11 11.2 sun4u sparc SUNW,SPARC-Enterprise But, i dont get any... (20 Replies)
Discussion started by: mohtashims
20 Replies

3. UNIX for Dummies Questions & Answers

Grep a specific process name

Hello, I want to grep a specific process named "TEST" in AIX but not only is it showing what I want but also listing others that have the similar name. How can I only list "TEST"? I've tried using options grep -w with no change and grep -o isn't supported in my environment. Please advise. ... (6 Replies)
Discussion started by: seekryts15
6 Replies

4. Shell Programming and Scripting

Grep process with two strings

Hi, I am trying to get the PID of a process that is defunct. I have two quesitons on this. 1) how do I pass in two strings? This is what I am using now: ps -ef |egrep -i "programname|<defunct>" But this returns multiple results with the word defunct in them. 2) How do I make it so that... (1 Reply)
Discussion started by: ChickenPox
1 Replies

5. UNIX for Dummies Questions & Answers

Grep the process id

Hi How to grep the process id and take it as a variable.i tried to get the value 9953 to a variable and could not with my little bit of linux exp,can any one help netstat -ptlen | grep 10000 tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN 0 ... (3 Replies)
Discussion started by: vikatakavi
3 Replies

6. Shell Programming and Scripting

Grep command to show only process name

Can I modify the grep command to show only a process name? Currently I run ps -efa | grep chk_web to get the following: mousr 3395 1 0 09:36:06 pts/10 0:00 sh /var/opt/scripts/chk_web.sh Can this be changed in any way to get only: /var/opt/scripts/chk_web.sh or chk_web.sh. I... (3 Replies)
Discussion started by: runnerpaul
3 Replies

7. Shell Programming and Scripting

grep the process id and kill all the filtered process

Hi I want to write a shell script which can find the process id's of all the process and kill them eg: ps ax | grep rv_ 3015 ? S 0:00 /home/vivek/Desktop/rv_server 3020 ? S 0:00 /home/vivek/Desktop/rv_gps 3022 ? S 0:00 /home/vivek/Desktop/rv_show ... (7 Replies)
Discussion started by: vivek_naragund
7 Replies

8. Shell Programming and Scripting

grep the number of self process

Dear All, I plan to write a script and in the beginning, I will check if there's any existing previous process running, if YEs, then exit directly, if Not, then continue. #!/bin/bash NUM=`ps -ef | grep $0 | grep -v grep | wc -l` ps -ef | grep $0 | grep -v grep echo "NUM ==> $NUM" if... (6 Replies)
Discussion started by: tiger2000
6 Replies

9. Shell Programming and Scripting

Kill a process from a grep

Soz im a bit newbie... I want to do: ps -A | grep firefox | kill $1 it should kill the pid associated, but it doesnt work. $1 is the pid (if i do a awk {'print $1'} i get it ) , but kill doesnt take it as such... How can i do it? (3 Replies)
Discussion started by: ierpe
3 Replies

10. UNIX for Dummies Questions & Answers

grep for a process

Hi, I want to grep within a script for a process. The problem is I just no the name of the process not its location. I tried the following: ps -ef | grep demo but than I get also processes which run from the directory demo or where I file like demo.c is open. So I am searching for... (3 Replies)
Discussion started by: bensky
3 Replies
Login or Register to Ask a Question