sub zConnectTo{ my($p_database,$p_login,$p_pass, $LOGF); $p_database=$_[0]; $p_login=$_[1]; $p_pass=$_[2]; print "$p_database\t$p_login\t$p_pass\n"; open($LOGF, ">>/path/LOG/InsertFileLog.txt") || die "$!"; my ($r_dbh); print $LOGF `pwd`; if($p_database eq 'db1') { $r_dbh = DBI->connect('dbi:Oracle:db1',$p_login,$p_pass); } elsif($p_database eq 'db2') { $r_dbh = DBI->connect('dbi:Oracle:db2',$p_login,$p_pass,{ RaiseErr +or => 1, AutoCommit => 0 }) || die "Database connection not made: $DB +I::errstr"; } print $LOGF "DB handler: $r_dbh\n"; print $LOGF "$p_database\t$p_login\t$p_pass\n"; close($LOGF); return $r_dbh; } sub zInsertInto_prep_all_mous{ my $p_dbh; $p_dbh=shift; my ($l_key, $l_value,$lComRec); my (@l_splitKey,@l_splitValue,@aggrData_all,$INRT); my ($l_count_records_time_start,$l_count_inserted_records,$ILOGF,$l_ +time); $l_count_records_time_start=time(); $l_count_inserted_records=0; open($ILOGF, ">>/path/LOG/InsertFileLog.txt") || die "$!"; print $ILOGF "\n**************Processing Started**************\n\n"; + while (($l_key, $l_value) = each %mainOutputHash ) { $l_count_inserted_records++; @l_splitKey = split(/,/,$l_key); @l_splitValue = split(/,/,$l_value); #print $ILOGF " Number of Records processed = $l_count_inserte +d_records\n"; #print $ILOGF "$l_splitKey[0],$l_splitKey[1],$l_splitKey[2],$l_spl +itKey[3],$l_splitKey[4],$l_splitKey[5],$l_splitKey[6],$l_splitValue[0 +],$l_splitValue[1],$l_splitValue[2],$l_splitValue[3]"; eval { $INRT = "insert into tablename values('$l_splitKey[0]','$l_splitKe +y[1]','$l_splitKey[2]','$l_splitKey[3]','$l_splitKey[4]','$l_splitKey +[5]', '$l_splitKey[6]','$l_splitValue[0]','$l_splitValue[1]','$l_spli +tValue[2]','$l_splitValue[3]',sysdate)"; $p_dbh->do("$INRT"); }; last unless $@; # no error: break out of the loop. #print $ILOGF "Data not inserted in table"; print $ILOGF $@ if $@; if($l_count_inserted_records%10000 == 0){ $lComRec = $lComRec + 1; $p_dbh->commit(); print $ILOGF "10000 Records Committed = $lComRec\n"; } } $l_time=zCalculateTime($l_count_inserted_records,$l_count_records_ti +me_start); print $ILOGF "\n**************".$l_time."**************\n"; print $ILOGF "\n******$l_count_inserted_records records have been In +serted in w_prep_mous_taiyaba******\n\n"; close($ILOGF); } #---------------------------------------------------------- # MAIN FUNCTION #---------------------------------------------------------- my($time_start,$time_end, $LOGF, $l_time, $IMD, $dirtoget, @filenames, + $f, $GLOGF); $dirtoget="/path"; open($LOGF, ">>/path/LOG/InsertFileLog.txt") || die "$!"; $time_start=time(); print $LOGF " Starting Date/Time "; print $LOGF `date`; close($LOGF); zRegion_City(); opendir($IMD, $dirtoget)|| die "$!"; my $string ='DailyPrepFULL'; @filenames=readdir($IMD); foreach $f (@filenames) { my $subString= substr($f,0,13); my $Strgzip = substr($f,-3); my $newFileName = substr($f,0,-3); if ($subString eq $string && $Strgzip eq '.gz') { open($GLOGF, ">>/path/LOG/GzipLog.txt") || die "$!"; print $GLOGF `date`; print $GLOGF "File is been kept as zipped\n"; print `gunzip $f`; print $GLOGF "File has been Unzipped\n"; print $GLOGF "Old Filename= $f\n"; $f=$newFileName; print $GLOGF "New Filename= $f\n"; close($GLOGF); } if ($subString eq $string) { zFetchAggrRows($dirtoget.$f); my $fileMoveFrom=$dirtoget.$f; my $fileMoveTo=$dirtoget.'Completed/'; #print `mv $fileMoveFrom $fileMoveTo`; } } $dbh=zConnectTo("db2","login","pswd"); open($LOGF, ">>/path/LOG/InsertFileLog.txt") || die "$!"; print $LOGF "DB Handler: $dbh\n"; close($LOGF); zInsertInto_prep_all_mous($dbh); open($LOGF, ">>/path/LOG/InsertFileLog.txt") || die "$!"; print $LOGF "After Insert Function\n"; close($LOGF); zCommit($dbh); zDisconnect($dbh); open($LOGF, ">>/path/LOG/InsertFileLog.txt") || die "$!"; $time_end=time(); $l_time=TotalExecutionTime($time_start,$time_end); print $LOGF "\n************** Total Execution Time: ".$l_time." ****** +********\n Closing Date/Time "; print $LOGF `date`; print $LOGF "\n"; close($LOGF);

In reply to Re^4: Need Help regarding perl script in unix cronjob... by waridtel
in thread Need Help regarding perl script in unix cronjob... by waridtel

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.