Skip to content

Instantly share code, notes, and snippets.

@kumarasinghe
Created April 30, 2020 10:40
Show Gist options
  • Save kumarasinghe/959542b3fd96d6dbc0006dfc3a8620b5 to your computer and use it in GitHub Desktop.
Save kumarasinghe/959542b3fd96d6dbc0006dfc3a8620b5 to your computer and use it in GitHub Desktop.
Cron Script to email torrent download progress
#!/usr/bin/perl
my $path = "/folder/to/monitor";
my $mailCMD = "/usr/bin/msmtp";
my $mailTo = 'you@gmail.com';
chdir $path;
my @files = `du -hs * | cut -f2`;
my @actualSizes = `du -hs * | cut -f1`;
my @apparentSizes = `du -hs --apparent-size * | cut -f1`;
my $out = "[$path]\n";
for my $i (0 .. $#files){
my $filename = $files[$i];
my $actualSize = $actualSizes[$i];
my $apparentSize = $apparentSizes[$i];
chomp $filename;
chomp $actualSize;
chomp $apparentSize;
$out = $out . "$actualSize / $apparentSize $filename\n";
}
$out .= "\n[DISK USAGE]\n" . `df -hl -x tmpfs --output=target,pcent`;
print $out;
system("printf \"Subject: Torrent Status\n%s\" \"$out\" | $mailCMD $mailTo");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment