Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Directory Monitor

by Corion (Patriarch)
on Jul 25, 2016 at 10:36 UTC ( [id://1168457]=note: print w/replies, xml ) Need Help??


in reply to Directory Monitor

The code you show cannot be the code you run. $file is never defined.

Do you really need to include MIME::Lite in the program? Is the problem with sending an email or is the problem with getting the events?

Please provide a short, self-contained program that we can run to reproduce your problem. It should be shorter than 20 lines.

Replies are listed 'Best First'.
Re^2: Directory Monitor
by perlmad (Sexton) on Jul 25, 2016 at 10:48 UTC

    Corion I have added short code , problem with event not email

    #! usr/bin/perl use strict; use warnings; use File::Monitor; use File::Monitor::Delta; use File::Monitor::Object; my $path="/tmp/abc"; my $monitor = File::Monitor->new(); # Watch a directory $monitor->watch( { name => $path, recurse => 1 } ); # First scan just finds out about the monitored files. No changes # will be reported. $monitor->scan; # Later perform a scan and gather any changes while ($path) { my @changes = $monitor->scan; for my $file ( @changes ) { chomp($file); my @file_changes; my @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"; } } }

      Personally, before checking for changes in file size, I would check and print what kinds of events the monitor sends you. Unfortunately, there is no easy way to ask the Delta about what it contains, so you will have to look at the raw contents using Data::Dumper and hope that they show what kinds of events get triggered by a change:

      for my $change (@changes) { use Data::Dumper; warn "Got a change:"; warn Dumper $change;

      Also, why are you calling chomp on an element of @changes? What do you expect @changes to contain?

        But The event is not working while update the file in the directory

        # Called when file size changes $monitor->callback( size => sub { my ($file_name, $event, $change) = @_; warn "$file_name has changed size\n"; } );

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1168457]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-03-28 10:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found