Tying it all together: Extracting SQL Batches, Highlighting Code with Kate, and Sending an email with attachments

In How to read batches of SQL from a file in Perl, we learned how to read a SQL file and extract individual batches and created the Perl module dbS::Sybase::Parse::SQL_File. In How to colorize your code using Perl and Syntax::Highlight::Engine::Kate, we learned how to make HTML highlighted arbitrary code and created Perl module dbS::misc. Finally, in Sending email with attachments from Perl – the easy way, we learned how to send email with attachments and created Perl module dbS::EMail.

Now, we are going to tie them all together so we can send ourselves colorized SQL code and a screenshot of an application going screwy!


use strict;
use warnings;

use File::Basename;

use dbS::EMail;
use dbS::misc;
use dbS::Sybase::Parse::SQL_File;

our $PROC = basename($0);


my $message = "";

if ( my $sql_batch = dbS::Sybase::Parse::SQL_File::get_batch("/dbms/sybase/ASE-15_0/scripts/installmontables", undef, 1) ) {
   while (my $query = $sql_batch->next ) {
      $message .= $query;
      $message .= "go\\n\\n";
} else {
   warn("unable to open the SQL file\\n");

if ( dbS::EMail::simple_send(
        $PROC . ': test HTML email',
        any_to_html('SQL', $message),
        { type => 'html', 'files' => "/tmp/AppBug.jpg" }
   )) {
   print "SUCCESS!  Email sent\\n";
} else {
   print "ERROR:  Email send failed\\n";
   printf "ERROR:  Email Transport: %s\\n", $dbS::EMail::error if $dbS::EMail::error;
   printf "ERROR:  Email Transport Log: %s\\n", $dbS::EMail::log if $dbS::EMail::log;
Share Button