[Chicago-talk] Inotify upon file upload?

David Mertens dcmertens.perl at gmail.com
Sun Nov 26 10:23:16 PST 2023


Looks good to me. Did it work? I know that later file access time is not
always recorded on the hard drive, but does inotify still get access
notifications?

As an aside, any reason you're not using the Perl built-on "rename" instead
of move() from File::Copy?

David

On Sat, Nov 25, 2023, 11:58 AM Richard Reina <richard at rushlogistics.com>
wrote:

> As it turn out Linux::Inotify2 <https://metacpan.org/pod/Linux::Inotify2> can
> get triggered by when a file is accessed. So here is what I came up with to
> detect when the file has been uploaded (accessed ) and then move it.
>
> use strict;
> use File::Copy;
>
> #waits for a waiting cvs file to be accessed and then moves it to old_cvs/
> directory
> use Linux::Inotify2;
> my $inotify = new Linux::Inotify2 or die $!;
> my $dir ='/home/richard/cvs_ready/';
>
> $inotify->watch($dir, IN_ACCESS) or die "No such dir: $dir: $!\n";
>
> while () {
>
>     my @events = $inotify->read;
>
>     unless (@events > 0){
>        print "read error: $!";
>        last ;
>     }
>
>     my $i = 0;
>     foreach my $event (@events) {
>
>     $i++;
>     if (substr($event->fullname, -1) ne  '/') { # they accessed an actual
> file, not just an 'ls' on the directory
>
>         print $event->fullname . " was modified\n" if $event->IN_ACCESS;
>         sleep 60;
>         print $event->fullname . " to /home/richard/old_cvs/\n";
>         move($event->fullname, "/home/richard/old_cvs/") or die "move
> failed: $!"; # move the file
>
>     }
>     }
>
> } # end of while
>
>
>
> On Thu, 23 Nov 2023 11:51:41 -0600, Richard Reina <
> richard at rushlogistics.com> wrote:
>
>
> Happy Thanksgiving All,
>
> With the proliferation of bank fraud. I am now required by my bank to
> upload a CVS file with all of my recent checks so that they can validate
> checks being presented to my account. I am automating this process, but one
> step that I am not able to complete is for my perl script to know once a
> file have been uploaded so that it can move to an indicated directory. I
> have used Linux::Inotify2 <https://metacpan.org/pod/Linux::Inotify2>;  but
> I don’t believe it will notify if a file is simply uploaded. Does anyone
> know of a way that a file could be slightly modified once it’s selected
> via websites API for upload so that my Perl script will know to move it to
> a different directory?
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> https://mail.pm.org/mailman/listinfo/chicago-talk
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> https://mail.pm.org/mailman/listinfo/chicago-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20231126/bbd51387/attachment.html>


More information about the Chicago-talk mailing list