Frinds.. this is my first post, will try to provide all details accurately and in the best format...

Final Output: Trying to query oracle db and list all tables created yesterday for particular db and email. If not tables created then email shouldn't send Currently using shell script to connect db, get outputfile from perl and email to user. It runs perfectly fine but sends email even there are no tables created.

Questions: 1. Want to only email user if any tables were created, if no table created then shell script shouldn't send any email?

2. In subroutine "putHeader" how to get db name dynamic as per login db, TEST db under subroutine is hardcoded which is not right?

3. any easier way to include send email part within perl only so as to have only 1 file?

FILENAME: run_list_tables.ksh #!/bin/ksh d=`date +%Y%m%d` log_dir=$HOME output_file=log.list list_tables -login /@testdb -outputFile $output_file mailx -s "list report : $d" test@mail < $output_file

PERL Script below

FILENAME: list_tables use strict; use Getopt::Long; use DBI; use DBD::Oracle qw(:ora_types); my $exitStatus = 0; my %options = () my $oracleLogin; my $outputFile; my $runDate; my $logFile; ($oracleLogin, $outputFile) = &validateCommandLine(); my $db = &attemptconnect($oracleLogin); &reportListTables($outputFile); $db->($exitStatus); #--------------------------- sub reportListTables { my $outputFile = shift; if ( ! open (OUT,">" . $outputfile)) { &logMessage("Error opening $outputFile"); } print OUT &putTitle; my $oldDB="DEFAULT"; my $dbcounter = 0; my $i; print OUT &putHeader(); #iterate over results for (my $i=0; $i<=$lstSessions; $i++) { # print result row print OUT &putRow($i); $dbCounter++; } print OUT &putFooter($dbCounter); print OUT " *** Report End \n"; closeOUT; } #------------------------------ sub putTitle { my $title = qq{ List Tables: Yesterday -------------- }; #------------------------------ sub putHeader { my $header = qq{ TESTDB ============== OWNER Table Created }; #------------------------------ sub putRow { my $indx = shift; my $ln = sprintf "%-19s %-30s %-19s", $lstSessions[$indx]{owner}, $lstSessions[$indx]{object_name}, $lstSessions[$indx]{created}; return "$ln\n"; } #------------------------------ sub getListTables { my $runDt = shift; my $rounter = 0; my $SQL = qq{ selct owner, object_name, to_char(created,'MM-DD-YYYY') from dba_o +bjects }; my $sth = $db->prepare (SQL) or die $db->errstr; $sth->execute() or die $db->errstr;; while (my @row = $sth->fethcrow_array) { $lstSessions[$rcounter] {owner} =$row[0]; $lstSessions[$rcounter] {object_name} =$row[1]; $lstSessions[$rcounter] {created} =$row[2]; &logMessage(" Owner: $lstSessions[$rcounter]{owner}"); &logMessage(" Table: $lstSessions[$rcounter]{object_name}"); &logMessage(" created: $lstSessions[$rcounter]{created}"); $rcoiunter++; } &logMessage("rcounter records found..."); }

In reply to List DB tables by homer4all

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.