#!/usr/bin/perl -w use strict; use lib '/home/student/tmp2604/lib'; use Linux::Inotify2; use File::Find; my @results = "/home/student/tmp2604/ntest/"; File::Find::find({wanted => \&wanted}, '/home/student/tmp2604/ntest/'); print "@results\n"; sub wanted { if (lstat($_) && -d && (/^in\z/ || /^out\z/) ) { push(@results, $File::Find::name); } } my $inotify = new Linux::Inotify2 or die "unable to create new inotify object: $!"; foreach my $jail (@results){ $inotify->watch($jail, IN_CLOSE_WRITE|IN_CREATE|IN_DELETE) or die "watch creation failed for $jail" ; } while () { my @events = $inotify->read; unless (@events > 0) { print "read error: $!"; last ; } foreach (@events) { printf "mask: %s name: %s fullname:%s\n", $_->mask, $_->name, $_->fullname ; my $name = $_->name; if ( $name =~ m/^\d+$/ ) { sleep 5; my $myin = "/home/student/tmp2604/ntest/$name/in"; my $myout = "/home/student/tmp2604/ntest/$name/out"; printf "in:%s\tout:%s\n", $myin ,$myout; $inotify->watch($myin, IN_CLOSE_WRITE|IN_CREATE|IN_DELETE) or die "watch creation failed for $myin" ; $inotify->watch($myout, IN_CLOSE_WRITE|IN_CREATE|IN_DELETE) or die "watch creation failed for $myout" ; } } }