I have a bunch of apache access log files and I want to know which IP addresses visited my /contacts folder. How can I collect them from all log files with shell command?
Asked
Active
Viewed 799 times
0
-
you may find this helpful: http://serverfault.com/questions/11028/do-you-have-any-useful-awk-and-grep-scripts-for-parsing-apache-logs/ – pete Mar 09 '16 at 13:17
-
show example of your log – user1700494 Mar 09 '16 at 13:18
1 Answers
2
Just use simple grep and awk command to filter records and show IPs. For common log format you can use something like this:
cat /path/to/apache/accesslog/dir/* |grep "/contacts" |awk '{ print $1 }' |sort -u
Or there is better way - setup some central logging and analyzing tool (like ELK stack) and use it for global analyzing across time and data.
Ondra Sniper Flidr
- 2,623
- 11
- 18
-
1UUOC and UUOG ;) `awk '/contacts/ {print $1} /path/to/apache/accesslogdir/*` – user9517 Mar 09 '16 at 21:47
-
maybe too complicated but I cannot remember higher syntax of awk that this to "print field number x in stdin and print it out" so this works for me. – Ondra Sniper Flidr Mar 10 '16 at 16:36