Commit e8ee55c7 authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Add debugging option (-d) to prevent emailing output. Nicer for

development.
parent 0aa3ea21
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group. # Copyright (c) 2000-2003 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use English; use English;
use Getopt::Std;
# #
# Audit the DB, looking for things we want to catch. Run once a day from cron. # Audit the DB, looking for things we want to catch. Run once a day from cron.
# #
sub usage() {
print STDOUT "Usage: audit [-d]\n".
"Use the -d option to see debugging output instead of emailing it.\n";
exit(-1);
}
my $optlist = "d";
my $debug = 0;
# #
# Configure variables # Configure variables
...@@ -39,6 +46,21 @@ if ($UID != 0) { ...@@ -39,6 +46,21 @@ if ($UID != 0) {
exit(-1); exit(-1);
} }
#
# Parse command arguments. Once we return from getopts, all that should
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (@ARGV) {
usage();
}
if (defined($options{"d"})) {
$debug++;
}
# #
# Form a temp name. # Form a temp name.
# #
...@@ -49,8 +71,10 @@ my $query_result; ...@@ -49,8 +71,10 @@ my $query_result;
# Reopen both stdout and stderr so that we can record all the output for # Reopen both stdout and stderr so that we can record all the output for
# later mailing. # later mailing.
# #
#open(STDERR, ">> $logname") or die("opening $logname for STDERR: $!"); if (! $debug) {
#open(STDOUT, ">> $logname") or die("opening $logname for STDOUT: $!"); open(STDERR, ">> $logname") or die("opening $logname for STDERR: $!");
open(STDOUT, ">> $logname") or die("opening $logname for STDOUT: $!");
}
# #
# Look for experiments running longer than 1 day, using real nodes. # Look for experiments running longer than 1 day, using real nodes.
...@@ -95,12 +119,13 @@ if ($query_result->numrows) { ...@@ -95,12 +119,13 @@ if ($query_result->numrows) {
# #
# Send email if anything was reported. # Send email if anything was reported.
# #
if (-s $logname) { if (!$debug && -s $logname) {
SENDMAIL($TBOPS, "Testbed Audit Results", "Testbed Audit Results", SENDMAIL($TBOPS, "Testbed Audit Results", "Testbed Audit Results",
$TBOPS, undef, ($logname)); $TBOPS, undef, ($logname));
} }
unlink("$logname"); unlink("$logname")
if (-e $logname);
exit 0; exit 0;
sub fatal($) { sub fatal($) {
...@@ -108,6 +133,7 @@ sub fatal($) { ...@@ -108,6 +133,7 @@ sub fatal($) {
print STDERR "$msg\n"; print STDERR "$msg\n";
SENDMAIL($TBOPS, "Testbed Audit Failed", $msg, undef, undef, ($logname)); SENDMAIL($TBOPS, "Testbed Audit Failed", $msg, undef, undef, ($logname));
unlink("$logname"); unlink("$logname")
if (-e $logname);
exit(1); exit(1);
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment