LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   grep command (https://www.linuxquestions.org/questions/linux-general-1/grep-command-45095/)

cuss 02-12-2003 12:06 PM

grep command
 
Hi,

Is there a way to use grep so that I can query 2 patterns at one time for correlation purposes? For example, I want to query system message %PIX-3-315001 and IP x.x.x.x to see how many times that particular IP had a denied SSH login attempt against it. I've tried a few different things but no luck. I assume it can be done and is probably an issue of inexperience on my part. For, example if there are 10 %PIX messages and 10 IP x.x.x.x messages in the logfiles, but only 3 of those 20 messages containg both %PIX and IP x.x.x.x then those are the only ones I want to see.

Thanks.

acid_kewpie 02-12-2003 12:44 PM

just use a slightly more complex regex:

grep PIX.+x.x.x.x LOGFILE

see the grep manpage for a guide on writing regex's

cuss 02-12-2003 01:32 PM

Actually the command that works is as follows:

# grep %PIX-3-315001.*x\.x\.x\.x logfile

Thanks!

acid_kewpie 02-12-2003 01:48 PM

of course, silly me.

cuss 02-13-2003 09:12 AM

Interesting.....the command that worked for me yesterday doesn't return any results today (and it should). Would anyone have any clue as to why? The command is below.

# grep %PIX-3-315001.*x\.x\.x\.x logfile

Mik 02-13-2003 10:12 AM

Does the logfile actually still contain those entries? Has the logfile been rotated?

There doesn't seem to be anything wrong with the grep syntax.

cuss 02-13-2003 10:33 AM

That's what i don't understand.....there has been no log rotation and the entries are still there. Don't know what to make of it?

cuss 02-14-2003 09:23 AM

Did this and it worked again.

# grep x\.x\.x\.x.*%PIX-3-315001 logfile

It's basically the reverse order of what first worked for me, but the logfile hasn't changed at all. It doesn't make sense to me but i got the results i want.


All times are GMT -5. The time now is 10:01 PM.