#!/usr/local/bin/perl5.004 -w
# 	$Id: WP_monthly_reports.pl,v 1.4 2003/03/06 08:52:11 ja1 Exp $	
#######################################################################
# this software has been created by genome research limited (grl).    # 
# grl hereby grants permission to use, copy, modify and distribute    # 
# this software and its documentation for non-commercial purposes     # 
# without fee at the user's own risk on the basis set out below.      #
# grl neither undertakes nor accepts any duty whether contractual or  # 
# otherwise in connection with the software, its use or the use of    # 
# any derivative, and makes no representations or warranties, express #
# or implied, concerning the software, its suitability, fitness for   #
# a particular purpose or non-infringement.                           #
# In no event shall the authors of the software or GRL be responsible # 
# or liable for any loss or damage whatsoever arising in any way      # 
# directly or indirectly out of the use of this software or its       # 
# derivatives, even if advised of the possibility of such damage.     #
# Our software can be freely distributed under the conditions set out # 
# above, and must contain this copyright notice.                      #
#######################################################################
#
# Monthly cronjob to run slow Oracle monthly throughput reports for Chris Clee
#
# Note that the second (wpLoader) job output should be mailed to Chris Clee ONLY
#
# Intended to be run from a crontab entry like the following:-
# 30 4 1 * * csh -c 'source $HOME/.login;/usr/local/badger/bin/WP_monthly_reports.pl'
#
# It will always report on the last complete month before the current one, so must be
# run sometime early in each new month.

use strict;
use Date::Calc qw(Parse_Date Add_Delta_Days);


my ($ss, $mi, $hh, $d, $m, $y) = localtime();

#
# work out the month and year of the day before the first of the current month
#
my ($yy, $mm, $dd) = Add_Delta_Days($y + 1900 ,$m + 1, 1, -1);

my $mon = (qw(JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC))[$mm - 1];

my $wpThruput = `/usr/local/badger/bin/wpThruput.pl $mon $yy`;

my $now = scalar localtime();

open (SENDMAIL, "| /usr/lib/sendmail -t -n") || die "Can't open /usr/lib/sendmail: $!\n";
print SENDMAIL <<EOFile;
To: cmc ci1
Cc: ja1
Reply-To: ja1
Subject: WP Throughput report for $mon $yy

$wpThruput

End of report at $now
EOFile
close(SENDMAIL);

my $wpLoader = `/usr/local/badger/bin/wpLoader.pl $mon $yy`;

$now = scalar localtime();

open (SENDMAIL, "| /usr/lib/sendmail -t -n") || die "Can't open /usr/lib/sendmail: $!\n";
print SENDMAIL <<EOFile;
To: cmc
Cc: 
Reply-To: ja1
Subject: WP Loader report for $mon $yy

$wpLoader

End of report at $now
EOFile
close(SENDMAIL);

