-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoveFilesToAWSStaging.pl
More file actions
executable file
·62 lines (56 loc) · 1.82 KB
/
moveFilesToAWSStaging.pl
File metadata and controls
executable file
·62 lines (56 loc) · 1.82 KB
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
#!/usr/bin/perl
use Net::SMTP;
use POSIX qw(strftime);
##############################################################
#
# Author : Zack Ramjan
# Company : Van Andel Institute
# Description:
# Find files and move them to staging area for archival
#
##############################################################
@dirs = ( "/varidata/research/projects/genomicscore/.archive");
$maxAge = 90;
my $ydm = strftime "%Y%m%d", localtime;
my $archiveDir = ".uploadToAWS_$ydm";
print $date;
for my $d (@dirs)
{
next unless -e $d;
chdir $d;
my @moveDirList = `find . -maxdepth 1 -type d -ctime +$maxAge`;
chomp @moveDirList;
next unless @moveDirList;
system("mkdir ../$archiveDir") unless -d "../$archiveDir";
system("chown \"marie.adams:sequencing-technology\" ../$archiveDir") if -d "../$archiveDir";
system("chmod 770 ../$archiveDir") if -d "../$archiveDir";
email("sequencing-notifications\@vai.org","$d files moved to $archiveDir, older than $maxAge days",join("\n",@moveDirList));
for $movedDir (@moveDirList)
{
next unless -e $movedDir && -d $movedDir;
system "mv \"$movedDir\" \"../$archiveDir\""
}
system("chmod -R 770 ../$archiveDir") if -d "../$archiveDir";
system("chown -R marie.adams:sequencing-technology ../$archiveDir") if -d "../$archiveDir";
}
sub email
{
my $toLine = shift @_;
my $from = "run.watch\@vai.org";
my $subject = shift @_;
my $message = shift @_;
my $smtp = Net::SMTP->new('smtp.vai.org');
my @to = split /,/, $toLine;
$smtp->mail($from);
if ($smtp->to(@to)) {
$smtp->data();
$smtp->datasend("To: $toLine\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
$smtp->datasend("$message\n");
$smtp->dataend();
} else {
print "Error: ", $smtp->message();
}
$smtp->quit;
}