grep filtering problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep filtering problem
# 1  
Old 06-30-2010
grep filtering problem

I'm working on writing a shell script that logs out whenever I have a firefox process running during certain times of the day (1 am - 8 am). I'll put it in crontab when it runs properly unless someone knows of a different and better way to do this. Here it is so far.

Code:
if ps ax | grep firefox-3.6.3
then 
echo hi
/usr/bin/gnome-session-save --kill --silent
exit 0 
fi

Its not working yet cause grep isn't filtering the way I need it to. This is what I get when firefox is running.
Code:
ps ax | grep firefox-3.6.3
 1859 ?        S      0:00 /bin/sh /usr/lib/firefox-3.6.3/firefox
 1864 ?        S      0:00 /bin/sh /usr/lib/firefox-3.6.3/run-mozilla.sh /usr/lib/firefox-3.6.3/firefox-bin
 1868 ?        Sl     1:45 /usr/lib/firefox-3.6.3/firefox-bin
 3374 pts/0    S+     0:00 grep --colour=auto firefox-3.6.3

This is what I get when firefox is not running.
Code:
ps ax | grep firefox-3.6.3
 3374 pts/0    S+     0:00 grep --colour=auto firefox-3.6.3

I need it to ignore the grep filtering process.
# 2  
Old 06-30-2010
Code:
if ps ax | grep '[f]irefox-3.6.3'

# 3  
Old 06-30-2010
Quote:
Originally Posted by vgersh99
Code:
if ps ax | grep '[f]irefox-3.6.3'

Works perfectly. Could you please explain why that works?

---------- Post updated at 06:01 PM ---------- Previous update was at 03:52 PM ----------

Also found that this works.
Code:
 ps -ef | grep firefox\$

https://www.unix.com/unix-dummies-que...p-process.html
# 4  
Old 07-08-2010
Could someone please explain why putting the f in square brackets got grep to filter the way I wanted it to?
# 5  
Old 07-08-2010
u can try this also -
ps ax|grep firefox-3.6.3|grep -v grep

Last edited by bmm04746; 07-08-2010 at 01:49 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed Or Grep Problem OR Terminal Problem?

I don't know if you guys get this problem sometimes at Terminal but I had been having this problem since yesterday :( Maybe I overdid the Terminal. Even the codes that used to work doesn't work anymore. Here is what 's happening: * I wanted to remove lines containing digits so I used this... (25 Replies)
Discussion started by: Nexeu
25 Replies

2. UNIX for Dummies Questions & Answers

Grep filtering issue

Hi, I am on uname -a HP-UX mymachine B.11.31 U ia64 3223107173 unlimited-user license ps -exx| grep java | grep -i "GrafiteEventsInterfaces*" 19955 ? 55:22 /opt/app/app1/jdk150_07/bin/IA64N/java -server -Xms1024m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m... (2 Replies)
Discussion started by: mohtashims
2 Replies

3. Shell Programming and Scripting

filtering awk not using grep

hallow all i have question about awk i want indexing last key (in BOLD number) ex: input.txt 1 252468812 52468812 1281268819 1252468812 1252468923 468812 1252468812 so output will like this output text 1:252468812 2:52468812 4:1252468812 6:468812 7:1252468812 output get... (8 Replies)
Discussion started by: zvtral
8 Replies

4. Shell Programming and Scripting

Problem with grep

I have the following ksh #!/bin/ksh file=$OBS_APP_PATH/config/com/uhg/obs/inbound/configs/XMLFile_ServiceFeeDetail.xml echo $file cntWrd=0 echo $cntWrd cntWrd= grep -c '<serviceFee>' $file echo $cntWrd while executing the above im getting the following error msg:... (2 Replies)
Discussion started by: balesh
2 Replies

5. Shell Programming and Scripting

Help with filtering trace file through grep

Hi, I am using NS2 and i need to filter a trace file (part of which is shown below): - 33.91576 2 3 tcp 1040 ------- 1 0.0 4.0 1115 2258 r 33.918907 4 3 ack 40 ------- 1 4.0 0.0 1107 2272 + 33.918907 3 2 ack 40 ------- 1 4.0 0.0 1107 2272 - 33.918907 3 2 ... (5 Replies)
Discussion started by: saqibshah
5 Replies

6. Shell Programming and Scripting

problem with grep |

Hi, When i try this it is not executing either result or total, pls can any one help me in this. max=month_134.log grep result|total $max > log.txt In month_134.log, it should contain either result or total and then send it to log.txt.It should execute result or total in log.txt ... (3 Replies)
Discussion started by: NehaKrish
3 Replies

7. UNIX for Advanced & Expert Users

grep problem

SQL*Plus: Release 9.2.0.8.0 - Production on Mon Jul 21 07:53:35 2008 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Connected to: Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production With the Partitioning option JServer Release 9.2.0.8.0 - Production SQL>... (3 Replies)
Discussion started by: infyanurag
3 Replies

8. UNIX for Dummies Questions & Answers

problem in filtering the file

-------------------------------------------------------------------------------- Hi, Plz help me out with this. I have some requirement like this..... I have a file like this... * CS sent email (11.20) CALYPSO 1031276 9076673 CDSHY FAILED Nov 19 2007 7:28AM OASYS: Unable to find CUSTOMER... (0 Replies)
Discussion started by: adityam
0 Replies

9. UNIX for Advanced & Expert Users

Difficult Filtering Problem

Sir, I have a file containing say 1000 lines that contain 100 paragraphs of 10 lines each separated by blank lines.I have to match a pattern or a string "hdfhasdjkasdhs" and print the complete paragraphs containing these strings.I can do this with the help of line editor ex,but how can I use... (1 Reply)
Discussion started by: Piyush
1 Replies

10. Shell Programming and Scripting

Grep problem

Folks, I need to resolve a problem I'm having with the grep command. The solution I currently have is: grep -Ei ' fail | error ' But the problem with this command is that, it doesn't catch strings like failed, failure, failing, etc. So my question is what's the best way to... (3 Replies)
Discussion started by: odogbolu98
3 Replies
Login or Register to Ask a Question