Month: July 2012

Parse FTP server log and send mail for every uploaded files

Parse FTP server log and send mail for every uploaded files

Introduction –

One of my friend was looking for script to parse FTP server log after every 10mins and send mail for every file uploaded by user
with Username, Uploaded File Name, Date and Size.  Please prefer the follow perl script to this task….

Download ftp file from here – http://www.indiangnu.org/wp-content/uploads/2012/ftp_logparser-pl.txt

1] Script –

arunb@mylaptop:~$ cat perl-prog/ftp_logparser.pl

#!/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";
arunb@mylaptop:~$

2] How to Use –

arunb@mylaptop:~$ ./perl-prog/ftp_logparser.pl

* Usage: ./perl-prog/ftp_logparser.pl

arunb@mylaptop:~$ ./perl-prog/ftp_logparser.pl /var/log/ftp.log

Thank you,
Arun Bagul

What are the mount options for databases on NetApp NFS

What are the mount options for databases on NetApp NFS

Introduction-
If you are using NFS (mount) volume/drive for Database, Then following mount options are recommended for databases on NetApp NFS:

Common mount options are = rw,bg,hard,rsize=32768,wsize=32768,vers=3

OS Mount Options for Binaires Mount Options for Oracle Datafiles
Solaris noac,nointr, proto=tcp, suid forcedirectio, noac,nointr, proto=tcp,suid
AIX nointr,timeo=600, proto=tcp cio,noac, nointr,timeo=600, proto=tcp
HPU noac,nointr, timeo=600, proto=tcp,suid forcedirectio, noac,nointr, timeo=600, proto=tcp, suid
Linux actimeo=0, nointr, suid, timeo=600, tcp actimeo=0, nointr, suid, timeo=600, tcp

Example –
root@myhost:~# cat /etc/fstab
arun_netapp07:/vol/db_vol /mydata nfs actimeo=0,nointr,suid,timeo=600,tcp,rw,bg,hard,rsize=32768,wsize=32768,vers=3 0 0

Thank you,
Arun Bagul