-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.pl
42 lines (40 loc) · 1.3 KB
/
check.pl
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
#!/usr/bin/perl
use strict;
use warnings;
use Archive::Tar;
use File::Basename;
my ($folderIn, $folderOut, $extension, $toExec) = @ARGV;
do {
opendir(DIR, $folderIn) or die $!;
while (my $file = readdir(DIR)) {
# We only want files
next unless (-f "$folderIn/$file");
# Use a regular expression to find files ending in .txt
next unless ($file =~ m/\.$extension$/);
# Verify is the file is not currently using
my $res = `lsof | grep $file | wc -l`;
if ($res == 0){
# Moving file(s?) into $folderOut
my $retVal = `mv $folderIn/$file $folderOut`;
# Execute whatever
$retVal = `perl $toExec $folderOut/$file`;
# Create a tar archive with all the files
my $tar = Archive::Tar->new;
$tar->add_files("./$folderOut/$file");
my ($name,$rep,$ext) = fileparse("$folderOut/$file", qr/\.[^.]*/);
$tar->add_files("./$folderOut/${name}.json");
# Renaming to avoid having $folderOut when extracting
$tar->rename("$folderOut/${name}.json", "${name}.json");
$tar->rename("$folderOut/${name}.tiff", "${name}.tiff");
# Write dat shit
$tar->write("$folderOut/${name}.tar");
# Remove the other files
$retVal = `rm -f $folderOut/$file $folderOut/${name}.json`;
}
else {
print "The file $file is currently open, waiting ...\n";
}
}
closedir(DIR);
sleep 1;
} while (1);