issue with grep command

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting issue with grep command
# 1  
Old 06-30-2011
issue with grep command

i am using 'psu' to grep the status of a process like below :-
psu|grep -i agentf
29559 29552 0 00:53:05 ? 0:57 gn1avm_agent -n AGENTF1
28946 1 0 00:51:31 ? 0:31 gnavm_ewd -b gn1avm_agent -n AGENTF1 -c -n AGENTF1
29552 28946 0 00:53:05 ? 0:00 /bin/ksh /olclocal/fs_users/tksfr01/abp_home/core/bin/gn1_preAvm_Ksh -b gn1avm_agent -c -n AGENTF1

out of these three process, RED process(first process) is IMP for me , i want to track this but problem is that - Orange colour process(2nd process) is also having same search pattern and it also comes with grep command .this orange process comes UP first and so my script/job checking 'psu' status shows - it's UP. but in fact , till now only Orange process is up not RED , RED process is still coming up and takes 2 more mins.

i want to check right status of RED process at right time.
if i use below command:-
psu | grep 'gn1avm_agent -n AGENTF1' | grep -v '\-c' | grep -v grep -> it gives right status , but now , it wil lbe treated as
psu | grep ‘gn1avm_agent -n AGENTF1| grep -v '\-c'' which will return nothing.
so how to grep it , my script checking this status is :-
DaemonPIDs=`ps -ex | grep -v -e grep | grep "${DaemonExeName}

ps -ex | grep -v -e grep | grep "gn1avm_agent -n AGENTF1"
29559 ? 0:59 gn1avm_agent -n AGENTF1
28946 ? 0:31 gnavm_ewd -b gn1avm_agent -n AGENTF1 -c -n AGENTF1

+ CheckDaemonStatus
+ + ssh host -l account -qn ps -ex
+ grep -w gn1avm_agent -n AGENTF1
+ grep -v -e grep -e amc1_vrts_gen_monitor_ksh -e opcmon

so hot to get rid of this problem , pls suggest.
# 2  
Old 06-30-2011
ps | grep "[g]n1avm_agent -n"

[g] just matches g, but won't match itself so you can take out the grep -v grep.
# 3  
Old 06-30-2011
thats ok, but my problem is not to get rid of grep process. above i mentioned two process , red and orange , they r using same search pattern , i want to check the UP status of red process, which is taking more time compared to orange colour process and so script shows its UP as soon Orange process comes up.
i want to get Actual Status of Red process.
# 4  
Old 06-30-2011
It won't match the orange process, or the third process, because of the -n. It will only match the red process.
# 5  
Old 06-30-2011
see now , still showing both:-
psu|grep "[g]n1avm_agent -n"
tksfr01 29559 29552 0 00:53:05 ? 1:04 gn1avm_agent -n AGENTF1
tksfr01 28946 1 0 00:51:31 ? 0:31 gnavm_ewd -b gn1avm_agent -n AGENTF1 -c -n AGENTF1
it will not work , the whole searching string is common in both process "gn1avm_agent -n AGENTF1"
# 6  
Old 06-30-2011
I see what you mean now.

The usual way to track these things would be to have the program in question generate a PID file, which you can use to see if the PID is still valid. Even if the program doesn't do that, you can use things like start-stop-daemon to do so for you.

Failing that:

psu | grep "[g]n1avm_agent -n AGENTF1$"

# 7  
Old 06-30-2011
yeah , i think this looks fine , let me try Smilie
Thanks a lot !!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue executing grep command on Solaris

more jdbc.xml <name>Fast_ds/DataSource</name> <property> <name>user</name> <value>COL_USER</value> </property>Command 1: grep -A1 '<name>user</name>' jdbc.xml|grep -v '<name>user</name>'|sed 's/\(<value>\|<\/value>\)//g'| sed -e 's/^*//'Output: Command 2: grep... (5 Replies)
Discussion started by: mohtashims
5 Replies

2. Shell Programming and Scripting

Issue using empty variable in grep command

Hi, I'm writing a shell script and trying to grep a variable value, it works fine as long as there is a value in /tmp/list.out which is captured in $DSK but sometimes the file tends to be empty and that is where I'm having an issue while using grep which returns nothing. I know I can use something... (15 Replies)
Discussion started by: mbak
15 Replies

3. UNIX for Dummies Questions & Answers

Grep issue

HI, I have a command to check a license file. License_print. In that file you get the headlines and all different licenses. Now i want to have things extracted from it. so i do like following: license_print | grep -iw -e "user" -e "admin" But i donīt want all lines where user is... (11 Replies)
Discussion started by: Tzwaj
11 Replies

4. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

5. Shell Programming and Scripting

Issue in grep

i have following pattern in file s6:s2 s2:s4 s1:s2:s3:s4:s5:s6 s1 . . Now i want to find occurence of each record in file like s6:s2 occurs twice {once in first record and both occur in 3 record as well} so output should be s6:s2 2 s2:s4 2 s1:s2:s3:s4:s5:s6 :1 s1 : 2 ... (7 Replies)
Discussion started by: sharad.40216
7 Replies

6. Shell Programming and Scripting


Hi im trying a GREP a varaiable which contains a file name and i search it in a list of .txt file and ifs its found the .txt file , it returns the name of the txt file name..the snippet im using is foreach my $files (glob('*.txt')) { open(my $fh1, $files) or die("Unable to open '$files':... (2 Replies)
Discussion started by: rajkrishna89
2 Replies

7. Shell Programming and Scripting

CUT Command and grep issue

I am trying to grep the oracle erros evry day from the logs file. My problem is : -rw-r----- 1 tibcolm tibco 17438361 Apr 5 11:59 RetryService-RetryService.log -rw-r----- 1 tibcolm tibco 245303 Apr 5 12:00 ResponseService-ResponseService.log -rw-r----- 1 tibcolm tibco 2122654 Apr 5 12:00... (4 Replies)
Discussion started by: neeraj617
4 Replies

8. UNIX for Dummies Questions & Answers

Grep command issue

How am I supposed to print with one Unix command the names (and only the names) of company JMT? Problems with scandinavian letters? By typing grep JMT url | egrep --only-matching ']+'I still have company name and + marks I should get rid of. I'd be very grateful of your help bacause I am new... (1 Reply)
Discussion started by: jht
1 Replies

9. HP-UX

Performance issue with 'grep' command for huge file size

I have 2 files; one file (say, details.txt) contains the details of employees and another file (say, emp.txt) has some selected employee names. I am extracting employee details from details.txt by using emp.txt and the corresponding code is: while read line do emp_name=`echo $line` grep -e... (7 Replies)
Discussion started by: arb_1984
7 Replies

10. UNIX for Dummies Questions & Answers

Grep issue

more Hello.txt it was a sunny way and i was about to go home. I need to grep and redirect to a new file all the text between 'sunny' and 'go' string above. Note: There may be multiple lines in between the string i need to grep between. If there are multiple 'go' strings it should grep till... (9 Replies)
Discussion started by: mohtashims
9 Replies
Login or Register to Ask a Question

Featured Tech Videos