-
Notifications
You must be signed in to change notification settings - Fork 11
/
plagger-perlsphere.cron
executable file
·51 lines (34 loc) · 1.26 KB
/
plagger-perlsphere.cron
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
#!/usr/bin/perl
# plagger-perlsphere.cron
# Runs Plagger and captures and emails any error output to the site admin.
# Suggested frequency: hourly.
use warnings;
use strict;
use File::Temp qw(tempfile);
my $lock_file = '/tmp/perlsphere.lck';
die "Already running ($lock_file exists)" if -e $lock_file;
open(FH, ">$lock_file");
print FH "Running... Perlsphere\n";
close(FH);
my $send_mail = 1; # 0 to disable
my $admin_email = '[email protected]';
my $conf = '/var/www/perlsphere.net/perlsphere.yaml';
my $logdir = '/var/www/perlsphere.net';
my ($TMP, $tmpfile) = tempfile();
# Run Plagger using our config and grab any STDERR into a temporary file.
system qq(/usr/local/bin/plagger -c $conf > $tmpfile 2>&1);
my ($sec, $min, $hour, $mday, $mon, $year) = gmtime(time);
$mon++; $year += 1900;
$_ = sprintf("%02d", $_) foreach ($sec, $min, $hour, $mday, $mon);
my $date = "$year-$mon-${mday}T$hour:$min:${sec}Z";
my $output = <$TMP>;
if ($output && $send_mail) {
system qq(mail -s "Plagger results for perlsphere.net at $date" $admin_email < $tmpfile);
}
open (my $LOG, '>>', "$logdir/plagger.log") or die $!;
print $LOG "$date: ";
print $LOG $output ? "not OK\n" : "OK\n";
print $LOG $output if $output;
close $LOG;
unlink $lock_file;
unlink $tmpfile;