[Chicago-talk] Inotify upon file upload?
Richard Reina
richard at rushlogistics.com
Sat Nov 25 08:57:57 PST 2023
As it turn out 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; 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20231125/2485173d/attachment.html>
More information about the Chicago-talk
mailing list