#!/usr/bin/perl # njarj.pl : http://njarj.org/contribute.html # typically executed "/usr/local/path/njarj.pl /var/log/maillog*" # or "/usr/local/path/njarj.pl /var/log/messages*" from crontab # may have to run as root to access /var/log files ### Change this section to your specific environment ### #Results file: set to the full path/file-name to store results file $filename = "/var/www/html/njabl.txt"; #UID and GID to own results file, from /etc/passwd @fileown = (500,500); #Permissions assigned to results file, usually leave alone $filemod = 0644; ### Shouldn't need to change anything else ### #Calculate yesterday's date localtime(time() - 24 * 3600) =~ /^\S+\s+(\S+\s+\S+)\s+/; $date = $1; #track found relays %addrs = (); unlink $filename; open OUTFILE, "> $filename"; while ($filein = shift(@ARGV)) { #open the next log file in the list open LOGFILE, "< $filein"; while () { #only look at sendmail lines from yesterday next unless (m/$date .* sendmail.* from=.* relay=/o); (@line) = split /,/; $relay = pop(@line); $relay =~ m/\[(\d+\.\d+\.\d+\.\d+)\]/; #print the relay IP addr if we find a new one print OUTFILE $1,"\n" if ($1 and !defined($addrs{$1})); $addrs{$1} = 1; } close LOGFILE; } close OUTFILE; #set the file ownership and permissions chown @fileown, $filename; chmod $filemod, $filename;