-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch_uploads_tarchive
executable file
·70 lines (61 loc) · 2.1 KB
/
batch_uploads_tarchive
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl -w
use strict;
use warnings;
#####Get config setting#######################################################
# checking for profile settings
if(-f "$ENV{LORIS_CONFIG}/.loris_mri/prod") {
{ package Settings; do "$ENV{LORIS_CONFIG}/.loris_mri/prod" }
} ##Possibly the script can exit if the prod doesn't exist
#######################################################################################
# define project space
my ($debug, $verbose) = (0,0);
my ($stdoutbase, $stderrbase) = ("$Settings::data_dir/batch_output/tarstdout.log", "$Settings::data_dir/batch_output/tarstderr.log");
my $stdout = '';
my $stderr = '';
while($_ = $ARGV[0], /^-/) {
shift;
last if /^--$/; ## -- ends argument processing
if (/^-D/) { $debug++ } ## debug level
if (/^-v/) { $verbose++ } ## verbosity
}
## read input from STDIN, store into array @inputs (`find ....... | this_script`)
my @inputs = ();
my @submitted = ();
while(<STDIN>)
{
chomp;
push @inputs, $_;
}
close STDIN;
my $counter = 0;
## foreach series, batch magic
foreach my $input (@inputs)
{
$counter++;
$stdout = $stdoutbase.$counter;
$stderr = $stderrbase.$counter;
#$stdout = '/dev/null';
#$stderr = '/dev/null';
## this is where the subprocesses are created... should basically run processor script with study directory as argument.
## processor will do all the real magic
$input =~ s/\t/ /;
$input =~ s/$Settings::tarchiveLibraryDir//;
my $command = "tarchiveLoader -globLocation -profile prod $Settings::tarchiveLibraryDir/$input";
##if qsub is enabled use it
if ($Settings::is_qsub) {
open QSUB, "| qsub -V -e $stderr -o $stdout -N process_tarchive_${counter}";
print QSUB $command;
close QSUB;
}
##if qsub is not enabled
else {
system($command);
}
push @submitted, $input;
}
open MAIL, "|mail $Settings::mail_user";
print MAIL "Subject: BATCH_UPLOADS_TARCHIVE: ".scalar(@submitted)." studies submitted.\n";
print MAIL join("\n", @submitted)."\n";
close MAIL;
## exit 0 for find to consider this -cmd true (in case we ever run it that way...)
exit(0);