I need to parse Apache log file to look for specific suspicious patterns (like SQL injections).
For example I’m looking for id='%20or%201=1;
I am using grep to check the log file for this pattern (and others) and because these logs are huge it takes a long amount of time
Here my command:
grep 'id=' Apache.log | egrep "' or|'%20"
Is there a better or a faster method or command I need use to make the search faster?
For starters, you don’t need to pipe your
grepoutput toegrep.egrepprovides a superset ofgrep‘s regular expression parsing, so you can just do this:Calling
egrepis identical to callinggrep -E.That may get you a little performance increase. If you can look for fixed strings rather than regular expressions, that might also help. You can tell grep to look for a fixed string with the
-Foption:But using fixed strings you lose a lot of flexibility.