Skip to content

Commit 92c6e15

Browse files
committedOct 3, 2016
Take mail address for reports from configuration.
1 parent ca6d49c commit 92c6e15

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed
 

‎examples/config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"backup": [
33
"host1.example.org",
44
"host2.example.org"
5-
]
5+
],
6+
"mail": "backupmail@example.com"
67
}

‎scripts/rsnapshot-tools_report_all

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@ require JSON;
1313
use constant {
1414
LOGPATH => '/var/log/rsnapshot.reports',
1515
CONFPATH => '/etc/rsnapshot-tools',
16-
MAIL => 'backupwatcher@example.org'
1716
};
1817

1918
# Read configuration:
2019
my @backups = ();
20+
my $mail;
2121
{
2222
my $jsonfn = File::Spec->catfile(CONFPATH, 'config.json');
23-
open my $fh, '<', $jsonfn;
23+
open(my $fh, '<', $jsonfn) or die("Cloud not open $jsonfn: $!");
2424
local $/ = undef;
25-
my $json = JSON::decode_json(<$fh>) or die "Could not decode $jsonfn\n";
25+
my $json = JSON::decode_json(<$fh>) or die("Could not decode $jsonfn");
2626
close $fh;
2727
my $backups = $json->{backup};
2828
@backups = @$backups;
29+
$mail = $json->{mail};
30+
if (! $mail) {
31+
die "Configuration parameter 'mail' not set, can not continue";
32+
}
2933
}
3034

3135
for my $config (@backups) {
@@ -36,7 +40,7 @@ for my $config (@backups) {
3640
next;
3741
}
3842
# Send logfile via Email
39-
my $cmd = sprintf('cat %s | mail -s "Backup report: %s" %s', $logfile, $config, MAIL);
43+
my $cmd = sprintf('cat %s | mail -s "Backup report: %s" %s', $logfile, $config, $mail);
4044
system($cmd);
4145
# Clean logfile
4246
$cmd = sprintf('echo "Weekly backup report for %s:\n" > %s', $config, $logfile);

0 commit comments

Comments
 (0)
Please sign in to comment.