Greeting, all,
I have a script which converts query output into Excel spread sheet which is
working fine, I am a UNIX scripting guy and I am having difficulty making some
simple changes to the script, hope I will get some help.
I want to send a email from the script only if it fetches any data excluding
header using
uuencode excel_dump_1.xls excel_dump_1.xls |mailx -s "blah blah.." [EMAIL
PROTECTED] which will send the excel spread sheet as an attachment.
Thanks in advance
#!/usr/bin/perl
use warnings;
use FileHandle;
use DBI;
use strict;
use Spreadsheet::WriteExcel;
#use Spreadsheet::WriteExcel::Big;
use Getopt::Long;
use constant LINES_PER_BOOK => 60001;
my $dbh1 = DBI->connect("dbi:Oracle:db1", "user1", "user1" ) or die "Can't make
1st database connect: $DBI::errstr\n";
$dbh1->{RowCacheSize} = 100;
my $sql=q{
select *
from table1
where status!='Active'
};
print "Preparing SQL\n";
my $sth = $dbh1->prepare($sql);
print "Executing SQL\n";
$sth->execute();
print "Creating Workbook\n";
my $workbook = Spreadsheet::WriteExcel->new(newWorkBookName());
die "unable to create workbook - $!\n" unless $workbook;
$workbook->set_tempdir('/home/user1/LC');
my $worksheet = $workbook->addworksheet();
my $colNames = $sth->{NAME_uc};
print "Fetching data\n";
my $rowCount=0;
my $lineCount=0;
$worksheet->write_row($lineCount,0,$colNames);
print "\n";
while( my $ary = $sth->fetchrow_arrayref ) {
print $rowCount;
print "." unless $rowCount++%1000;
if ( ++$lineCount >= LINES_PER_BOOK ) {
$workbook->close;
my $workBookName = newWorkBookName();
$workbook =
Spreadsheet::WriteExcel->new($workBookName);
die "unable to create workbook - $!\n" unless $workbook;
$worksheet = $workbook->addworksheet();
$lineCount=0;
$worksheet->write_row($lineCount,0,$colNames);
$lineCount=1;
print "\nNew Workbook: $workBookName\n";
}
$worksheet->write_row($lineCount,0,$ary);
}
print "\n";
$workbook->close;
$sth->finish;
$dbh1->disconnect;
{
my $workBookNumber = 0;
sub newWorkBookName {
return "/home/user1/LC/excel_dump_" . ++$workBookNumber . ".xls";
}
}
---------------------------------
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.