#!/usr/bin/perl use strict; use warnings; no warnings 'uninitialized'; my $argument = $#ARGV + 1 ; my $mylog_file = $ARGV[0]; if ( -f $mylog_file ) { print "\nChecking FTP log file for Upload files ~ $mylog_file"; open(FILE, "<$mylog_file") or die("\nFile not found : $! "); print "\nContent of file is....\n"; while() { chomp($_); ## Fri Jul 6 14:15:25 2012 [pid 27841] [vivek] OK UPLOAD: Client "172.30.1.76"," /squid-2 7-Template-v23.docx", 594488 bytes #print "\nLine=> $_"; if ($_ !~ /^\s*$/) { #print "\nLine=> $_"; if ($_ =~ m/(.*)\s+\[pid.*\]\s+\[(.*)\]\s+OK\s+UPLOAD:\s+Client\s+"(\d+.\d+.\d+.\d+)","(.*)",\s+(\d+)\sbytes.*/) { my ($mydate, $myser,$ipaddr, $file_upload, $file_size) = ($1,$2,$3,$4,$5); print "\n'$mydate' - '$myser' - '$ipaddr' - '$file_upload' - '$file_size'"; ## send mail my $CONTACTEMAIL = "abc\@xyz.com"; open(MAIL, "|/usr/sbin/sendmail -t"); print MAIL "To: $CONTACTEMAIL\n"; print MAIL "From: ftp\@abc.com\n"; print MAIL "Subject: File Uploaded- $file_upload"; #print MAIL "\nContent-type: text/html\n\n"; print MAIL "\nContent-type: text/plain\n\n"; print MAIL "\nFile Name: $file_upload"; print MAIL "\nFile Size: $file_size bytes"; print MAIL "\nUser: $myser"; print MAIL "\nIPaddr: $ipaddr"; print MAIL "\nDate: $mydate"; close(MAIL); } } } close(FILE); print "\nDone"; } else { print "\n * Usage: $0 \n"; } #end print "\n";