#! usr/bin/perl
use strict;
use warnings;
use File::Monitor;
use File::Monitor::Delta;
use File::Monitor::Object;
use Getopt::Long;
use Config::IniFiles;
use MIME::Lite;
$file_list[$#file_list]='';
$temp=join('/',@file_list);
$email_body=$email_body."\n File Name : $file_name , Path : ".$temp."\n";
print "\n\n File Name : $file_name , Path : ".$temp."\n";
}
$email_subject="Monitor Path : $path , Status : Added";
&email;
$email_subject='';
$email_body='';
undef @file_changes;
undef @file_list;
}
if($file->files_deleted){
#print $file->files_deleted, " deleted\n";
print "Files Removed \n";
@file_changes=$file->files_deleted;
$email_body="\nFiles Removed,\n";
for my $temp(@file_changes){
@file_list=split('/',$temp);
my $file_name=$file_list[$#file_list];
$file_list[$#file_list]='';
$temp=join('/',@file_list);
$email_body=$email_body."\n File Name : $file_name , Path : ".$temp."\n";
print "\n\n File Name : $file_name , Path : ".$temp."\n";
}
$email_subject="Monitor Path : $path , Status : Removed";
&email;
$email_subject='';
$email_body='';
undef @changes;
undef @file_list;
}
if($file->is_event('size')){
print "size change\n\n";
}
if ($file->is_size) {
my $name = $file->name;
my $old_size = $file->old_size;
my $new_size = $file->new_size;
print "$name has changed size from $old_size to $new_size\n";
}
}
}
####
[abc@linux0059 monitor]$ perl code.pl --c config.ini
Files Removed
File Name : same1 , Path : /tmp/abc/
Email send : abc@google.com
Files Created
File Name : same1 , Path : /tmp/abc/
Email send : abc@google.com
[abc@linux0059 monitor]$
####
[abc@linux0059 abc]$ ls
folder log same1 same.txt sample2.txt simple
[abc@linux0059 abc]$ rm same1
[abc@linux0059 abc]$ touch same1
[abc@linux0059 abc]$ echo "hai hello" > same1
[abc@linux0059 abc]$