Repository navigation
Expand file tree
/
Copy pathnotifyFileAge.pl
More file actions
executable file
·77 lines (65 loc) · 2.71 KB
/
Copy pathnotifyFileAge.pl
File metadata and controls
executable file
·77 lines (65 loc) · 2.71 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl
use Net::SMTP;
##############################################################
#
# Author : zack ramjan
# Company : Van Andel Institute
# Description:
# notify genomics staff is trash is full
#
##############################################################
@dirs = ( "/varidata/research/projects/genomicscore/Core_Research_RawData");
$maxAge = 180;
for my $d (@dirs)
{
next unless -e $d;
my $outfull = `find $d -maxdepth 1 -type d -mtime +$maxAge`;
#email("sequencing-storage-notifications\@vai.org","$d report on files older than $maxAge days",$outfull) if length($outfull) > 5;
email("zack.ramjan\@vai.org","$d report on files older than $maxAge days",$outfull) if length($outfull) > 0;
}
sub email
{
print STDERR "emailing\n";
# --- Configuration Settings ---
my $smtp_host = 'mail.smtp2go.com'; # Replace with your SMTP server
my $smtp_port = 587; # 587 (TLS/StartTLS) or 465 (SSL)
# Your SMTP username
my $username = `head -n 1 /varidata/research/admin/tools/genomicsCoreFileMgmt/.creds`;
chomp $username;
# Your SMTP password / App Password
my $password = `tail -n 1 /varidata/research/admin/tools/genomicsCoreFileMgmt/.creds`;
chomp $password;
my $toLine = shift @_;
my $from = "run.watch\@vai.org";
my $subject = shift @_;
my $message = shift @_;
# --- Connect to the SMTP Server ---
# If your server requires explicit SSL from the start (port 465), change 'ssl => 0' to 'ssl => 1'
my $smtp = Net::SMTP->new(
$smtp_host,
Port => $smtp_port,
Timeout => 30,
Debug => 1, # Set to 0 to disable verbose logs in production
ssl => 0 # Use 1 if using port 465
) or die "Could not connect to SMTP server: $!";
# --- Upgrade to Secure Connection (TLS) ---
# Most modern SMTP servers on port 587 require starting plain and upgrading to TLS
if ($smtp-tp_port == 587) {
$smtp->starttls() or die "Failed to upgrade connection via STARTTLS: " . $smtp->message();
}
# --- Authenticate ---
$smtp->auth($username, $password) or die "Authentication failed: " . $smtp->message();
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;
}