From richard at rushlogistics.com Thu Nov 23 09:51:41 2023 From: richard at rushlogistics.com (Richard Reina) Date: Thu, 23 Nov 2023 11:51:41 -0600 Subject: [Chicago-talk] Inotify upon file upload? Message-ID: <4AAA9A8D-1490-4DD9-9F75-1A1A592F76ED@rushlogistics.com> An HTML attachment was scrubbed... URL: From richard at rushlogistics.com Sat Nov 25 08:57:57 2023 From: richard at rushlogistics.com (Richard Reina) Date: Sat, 25 Nov 2023 11:57:57 -0500 Subject: [Chicago-talk] Inotify upon file upload? In-Reply-To: <4AAA9A8D-1490-4DD9-9F75-1A1A592F76ED@rushlogistics.com> References: <4AAA9A8D-1490-4DD9-9F75-1A1A592F76ED@rushlogistics.com> Message-ID: <1700931477.7h875ip88wskoo04@hostingemail.digitalspace.net> 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 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: From hal.wigoda at gmail.com Sat Nov 25 13:09:32 2023 From: hal.wigoda at gmail.com (Hal Wigoda) Date: Sat, 25 Nov 2023 15:09:32 -0600 Subject: [Chicago-talk] Inotify upon file upload? In-Reply-To: <1700931477.7h875ip88wskoo04@hostingemail.digitalspace.net> References: <1700931477.7h875ip88wskoo04@hostingemail.digitalspace.net> Message-ID: <04631542-B74C-43B6-9813-C06F52FD022F@gmail.com> An HTML attachment was scrubbed... URL: From dcmertens.perl at gmail.com Sun Nov 26 10:23:16 2023 From: dcmertens.perl at gmail.com (David Mertens) Date: Sun, 26 Nov 2023 13:23:16 -0500 Subject: [Chicago-talk] Inotify upon file upload? In-Reply-To: <1700931477.7h875ip88wskoo04@hostingemail.digitalspace.net> References: <4AAA9A8D-1490-4DD9-9F75-1A1A592F76ED@rushlogistics.com> <1700931477.7h875ip88wskoo04@hostingemail.digitalspace.net> Message-ID: 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 wrote: > 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 > _______________________________________________ > 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: From richard at rushlogistics.com Sun Nov 26 13:28:19 2023 From: richard at rushlogistics.com (Richard Reina) Date: Sun, 26 Nov 2023 15:28:19 -0600 Subject: [Chicago-talk] Inotify upon file upload? In-Reply-To: References: Message-ID: <35531C28-DB06-4928-8663-1DF89649193D@rushlogistics.com> An HTML attachment was scrubbed... URL: