Set timeout to 30s and redirect STDERR to log file

This commit is contained in:
Peter J. Holzer 2016-03-10 16:23:18 +01:00
parent ed7ae3b2c5
commit 41e2c4fa18
1 changed files with 9 additions and 1 deletions

View File

@ -10,6 +10,7 @@ use DBIx::SimpleConnect;
use Encode qw(:fallbacks encode);
use Getopt::Long;
use Pod::Usage;
use POSIX qw(strftime);
my $db = "default";
my $dir = ".";
@ -29,8 +30,12 @@ binmode STDOUT, ":encoding(UTF-8)";
chdir $dir or die "cannot chdir to $dir: $!";
}
}
my $errorfile = strftime("%Y-%m-%d %H:%M:%S%z.err", localtime);
open STDERR, ">:encoding(UTF-8)", $errorfile;
my $dbh = DBIx::SimpleConnect->connect($db, {RaiseError => 1});
my $dbh = DBIx::SimpleConnect->connect($db, {RaiseError => 1, PrintError => 0});
# this is intended to run from cron, so limit the time it can run.
$dbh->do("set statement_timeout to 30000");
my $overview
= $dbh->selectall_hashref("
@ -46,6 +51,8 @@ my $overview
open(my $fh, ">:encoding(UTF-8)", "index.html.$$");
print_header($fh);
say $fh "<h1>Disk usage for database $db</h1>";
say $fh "<div class='timestamp'>", strftime("%Y-%m-%d %H:%M:%S%z", localtime), "</div>";
say $fh "<table>";
say $fh "<tr class='header'>";
say $fh "<th class='name'>", "Schema", "</th>";
@ -80,6 +87,7 @@ for my $s (sort { $overview->{$b}{''}{total_size} <=> $overview->{$a}{''}{total_
say $fh "</table>";
close($fh);
rename "index.html.$$", "index.html";
unlink($errorfile); # if we get here, we are fine
exit(0);