-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck2.pl
More file actions
executable file
·46 lines (38 loc) · 836 Bytes
/
check2.pl
File metadata and controls
executable file
·46 lines (38 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl -w
use strict;
use warnings;
use Getopt::Std;
use File::Monitor;
my %opts;
getopt('dcs', \%opts);
die "correct usage: ./check.pl -d dir -c command [-s sleep]" unless $opts{d} and $opts{c};
# defaults to 5 sec:
$opts{s} = 5 unless $opts{s};
my $monitor = File::Monitor->new();
sub create {
opendir(my $dh, $opts{d}) || die "can't opendir $opts{d}: $!";
my @nodots = grep { !/^\./ && -f "$opts{d}/$_" } readdir($dh);
closedir $dh;
my $isopen;
foreach my $f (@nodots) {
$isopen = qx(lsof | grep $f | wc -l);
while ($isopen != 0) {
sleep(1);
$isopen = qx(lsof | grep $f | wc -l);
}
print "calling $opts{c} $opts{d}/$f!\n";
}
}
$monitor->watch( {
name => $opts{d},
recurse => 0,
files => 1,
callback => {
files_created => \&create,
}
}
);
while (1) {
sleep $opts{s};
$monitor->scan;
}