perlmad has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks!!!
I have been using File::Monitor perl module to monitor a directory and its working well when create or delete a file to a given directory ,if i update a file it shows nothing and i have referred all the links but i don't know what i did wrong
Here is my code
#! 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 : $fil +e_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 : $fil +e_name , Path : ".$temp."\n"; print "\n\n File Name : $file_name , Path : +".$temp."\n"; } $email_subject="Monitor Path : $path , Status : Remove +d"; &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"; } } }
Actual Output
[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]$
Monitor Directory
[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]$
Response Much appreciated!!!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Directory Monitor
by Corion (Patriarch) on Jul 25, 2016 at 10:36 UTC | |
by perlmad (Sexton) on Jul 25, 2016 at 10:48 UTC | |
by Corion (Patriarch) on Jul 25, 2016 at 11:00 UTC | |
by perlmad (Sexton) on Jul 25, 2016 at 11:28 UTC | |
by Corion (Patriarch) on Jul 25, 2016 at 11:32 UTC |