#!/usr/bin/perl -w use Linux::Inotify2; use File::Find (); use strict; use vars qw/*name *dir *prune/; *name = *File::Find::name; *dir = *File::Find::dir; *prune = *File::Find::prune; sub wanted; my @results = '/home/tink/files/'; File::Find::find({wanted => \&wanted}, '/home/tink/files/'); print "@results\n"; sub wanted { my ($dev,$ino,$mode,$nlink,$uid,$gid); (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -d _ && ( /^in\z/s || /^out\z/s ) && push(@results, $name); } our $inotify = new Linux::Inotify2 or die "unable to create new inotify object: $!"; my @result; foreach my $jail (@results){ $inotify->watch($jail, IN_CLOSE_WRITE|IN_CREATE|IN_DELETE) or die "watch creation failed" ; } while () { my @events = $inotify->read; unless (@events > 0) { print "read error: $!"; last ; } foreach (@events) { printf "mask\t%d\t\%s\t%s\n", $_->mask, $_->name, $_->fullname ; if ( $_->fullname =~ m@(/home/tink/files/[0-9]{9})@) { sleep 5; my $myin = "'".$1."/in'"; my $myout = "'".$1."/out'"; printf "%s\t%s\n", $myin ,$myout; $inotify->watch($myin, IN_CLOSE_WRITE|IN_CREATE|IN_DELETE) or die "watch creation failed" ; $inotify->watch($myout, IN_CLOSE_WRITE|IN_CREATE|IN_DELETE) or die "watch creation failed" ; } } }