
asandybox
Novice
Jun 19, 2012, 8:53 AM
Views: 7718
|
|
Re: [FishMonger] Stuck on how to iterate a list in a file against a logfile.
|
|
|
Thanks Fishmonger, Still not getting any hits. Here is some sample data:
1323666001.661 172 192.168.1.47 TCP_MISS/200 3625 GET http://help.example.com.org/search/sss? - DIRECT/208.82.238.129 text/html 1323666001.985 238 192.168.2.47 TCP_MISS/304 237 GET http://www.example.com.org/styles/craigslist.css? - DIRECT/208.82.238.130 - 1323666002.310 165 192.168.3.47 TCP_CLIENT_REFRESH_MISS/304 237 GET http://www.example.com.org/js/jquery-1.4.2.js - DIRECT/208.82.238.130 - 1323666002.683 158 192.168.4.47 TCP_CLIENT_REFRESH_MISS/304 237 GET http://www.example.com.org/js/toChecklist.js - DIRECT/208.82.238.130 - 1323666002.999 164 192.168.5.47 TCP_CLIENT_REFRESH_MISS/304 235 GET http://www.example.com.org/js/jquery.form-defaults.js - DIRECT/208.82.238.130 - 1323666003.308 165 192.168.6.47 TCP_MISS/304 237 GET http://www.example.com.org/js/tocs.js? - DIRECT/208.82.238.130 - 1323666003.656 161 192.168.7.63 TCP_MISS/301 404 GET http://g.msn.com/1ewenus50/news7? - DIRECT/207.46.216.54 - 1323666003.991 12 192.168.8.63 TCP_MISS/200 1168 GET http://rss.msnbc.msn.com/id/3054049/device/rss? - DIRECT/205.128.86.254 application/rss+xml 1323666006.596 4 192.168.12.30 TCP_HIT/200 213 HEAD ftp://anonymous@ftp.example.com - NONE/- text/html and ip.txt looks like:
192.168.1.47 192.168.2.47 192.168.3.47 192.168.4.47 192.168.5.47 192.168.6.47 192.168.7.63 192.168.8.63 192.168.12.30 Here is what I think occurring with your code. 1. Your loading the ip addresses into a hash called "ip" 2. looping through the list to strip of any new lines. The next while loop allows us to to parse the input log file. I am unsure why you are splitting here: my $ip = (split(/\s/, $_))[2]; The remainder of the code is checking if the key value is in the data to be parsed. However, when I run ./mungelog.pl sample.txt I get no results. However clearly the IP addresses in the ip.txt file are present in the log file. Thanks again for all the help on this.
(This post was edited by asandybox on Jun 19, 2012, 8:55 AM)
|