Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Finding and Printing Data to Email in perl

Posted on 2011-10-14
2
Medium Priority
?
132 Views
Last Modified: 2012-05-12
Hi,

Below script reads a log file and compare the Data from the log file with the Oracle tables.

Can someone help to extent the script in a way that :

After comparing if it finds some Data unmatched it has to send an email with the Body of the email as:
      log: 17
      DB: 16
            list of not found id :
            id1
               id2...

[b]Script:[/b]
#!/local/bin/perl
use strict;
use warnings;
use DBI;


my $dir = '/usr/home/Scripts/Test';


# get the text files from the specified dir
opendir DIR, $dir or die "could not open directory $dir: $!";
my @files = grep /\.txt$/, readdir DIR;
closedir DIR;


my $dbh = DBI->connect("dbi:Oracle:****", "****", "*****" )
    || die( $DBI::errstr . "\n" );
$db->{AutoCommit}    = 0;
$db->{RaiseError}    = 1;
$db->{ora_check_sql} = 0;
$db->{RowCacheSize}  = 16;

foreach my $fil (@files) {

# read the ids from the files

    open IN, "$dir/$fil" or die "could not read $fil: $!";

   #my @ids = map { chomp; "'$_'" } <IN>;

    my @ids = map { "'$_'" } map { chomp; split /\s+/ } <IN>;

 
print "checking ", scalar(@ids), " ids from $fil\n";
print"@ids\n\n";
    

my $sel=$db->prepare("select (number||'/'||id) as List_ID from Info where List_ID in (" . join(', ', @ids) . ')');
   $sel->execute();
while(my $subref = $SEL->fetchrow_hashref()) {
    my $list=$subref->{'LIST_ID'};
print "$list\n";

}

Open in new window

0
Comment
Question by:new_perl_user
2 Comments
 

Author Comment

by:new_perl_user
ID: 36979990

Hi,

can some one please help with the above issue..
0
 
LVL 4

Accepted Solution

by:
kyanwan earned 2000 total points
ID: 37104870
I don't know if you gave up or nobody answered ...

But - You can manually create a well formed e-mail message, then pipe your output to sendmail.

Here's how you pipe to sendmail:  

open(MAIL,"|/path/to/sendmail -t"); # Open a pipe to Sendmail.  This is done via the |  
print MAIL "From: $email \n"; 
print MAIL "To: $recipient\n";
print MAIL "Reply-To: $email\n";
print MAIL "Subject: $subject\n";
# Create the standard headers 
print MAIL "X-Header: Put your custom headers here\n";
print MAIL "\n"; # End the headers with a double-newline. 
print MAIL << "END_DATA";

Put all of your mail text here. 

You can use print lines, or a print block like this. 

Stick your $vars in here , etc.... 

END_DATA

print MAIL "Variables not found: \n";
$counter = 0; 
foreach $var (@array) { 
	print MAIL "" . ($counter++) . ": $var\n";
}
close (MAIL);  # Finish your message. 

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question