Created
March 6, 2015 05:45
-
-
Save jamesandariese/a4a8c18b79f4ae5794c0 to your computer and use it in GitHub Desktop.
Awk for apache logs, time stuff, too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# awk field separator for a slightly customized apache access log (the :443 is the custom part) | |
awk -F ':443 |" |[][]| - - | [0-9][0-9]* "-"' | |
# For your average apache log with square brackets around the date, this will give you the log | |
# entries for the seconds around the entries you pipe into awk at the beginning | |
# replace BADNESS_HERE with whatever you want to find seconds around. | |
# | |
# NOTE: this can also be used to find things that happened within the seconds around 5 minutes | |
# before the event by changing s/$/p1-p2+p/ to s/$/300-p1-p2+p/ and other interesting | |
# things. | |
grep -Ff <(grep BADNESS_HERE access.log | awk -F ' [|] ' '{print $2}' | xargs -i date --date={} +%s |sed -e 's/$/p1-p2+p/'| dc | xargs -i date --date=@{} +'[%d/%b/%Y:%H:%M:%S -0800]') access.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment