I am trying to parse a squid log file to let It management know where people are browsing too. my plan block diagram goes a follows 1. open log 2. seperate by IP address , list only one at a time no repeats of the same IP address 3. list only one instance of a visited site , per IP address 4. print HTML file but I guess the best route would be dump each log entry in its own array ( by ip address of client machine) but I am not getting the desired results . I have a file for debuging called scratch.txt here is the code open(LOG,"</var/log/squid/access.log"); @logmess = <LOG>; close(LOG);
#### open XML log for writing open(LOGXML,">/var/log/squid/access.xml"); print LOGXML "<?xml version=\"1.0\"?>\n"; print LOGXML "<list>\n"; ############## ## open scratch open(scratch,">/var/log/squid/scratch.txt"); foreach $message(@logmess) { chomp($message); @fields = split(/\s+/, $message); $time = $fields[0]; $site_visited = $fields[6]; $userip = $fields[2]; $userip1 = $userip; $userip1 =~ s/\./_/g; $xml_ip = $userip1.".txt"; @scratch = "test"; # dump into array #do loop search foreach $el(@scratch){ $found = "no"; print "IP : $xml_ip ... $el\n"; if($xml_ip eq $el) { $found = "yes"; print "Yes !!\n"; } if($found ne "yes") { push(@scratch, $xml_ip); } } foreach $rt(@scratch){ print scratch "$rt\n"; } close(scratch); open(XML_IP,">>$xml_ip"); # holding file per IP addresses $fetch = $fields[8]; $type = $fields[9]; ######################################################### ## Dump each into its own variable ## ######################################################### @visited = split(/\//,$site_visited); # add date , dump into array print XML_IP "$userip $visited[2]\n"; close(XML_IP); my scratch file looks like this test 192_168_1_68.txt there are more clients that that any suggestions ? thanks Jim