This program is supposed to print the date to a file and then the data it parses out of access.log and instead prints out the data it parses, and then the date. Sry, I've been playing with perl for , oh say, three days now.
#!/usr/bin/perl -w
use diagnostics;
#This file parses out squids access log for address bar entries to see where users purposefully go
$date=`date`;
$net="192.168.4.";
$counter=10;
$logpath="/var/log/squid/userarchive/";
$ip=$net.$counter;
#The counter is set to the max ipadress +1
while ( $counter <= 14 ) {
#Print the date to each file we're writing to
open(LOGF,">>",$logpath . $ip);
print LOGF "$date\n";
$|++;
close LOGF;
#Grab the access log and go through it, splitting each line into elements of the array
open(INFILE,"/var/log/squid/access.log") or die "Can't open /var/log/squid/access.log: $!";
while ( <INFILE> ) {
@array = split(" ",);
$ip=$net.$counter;
#Only grab things associated with the current searched for ip and ends with .com .net and so on
if (($array[7] =~ /[com|org|net|gov|cc|mil]\/$/)&&($array[3] eq $ip)) {
#Write it to the log file
open(LOGF,">>",$logpath . $ip) or die "Can't open $logpath$ip: $!";
print LOGF "$ip \: $array[0] $array[7]\n";
close LOGF;
}
}
$counter++;
}
I open one file, write to it, close it and then run my loop, but it seems to do this backwards. Anyone?