FAQ
Hello Everyone:

I have a Perl script that connects to multiple Oracle databases. I have the script write some status information to
a log file. There is one particular database that hangs in processing, and I don't know why. The log file does not seem
to be written until the file is closed.

I am wondering, is there a Perl command or technique that will force lines that are logically written to a log file to be
physically written to that file?

Here's my opening code:
#
# -------------------------------------------------------------------------
# Open Log file
# -------------------------------------------------------------------------
my $logFileName = "${HomeDir}/work/monitor/output/logs/db_status.log";
open( LOGF, ">>" . $logFileName ) or die "\nCannot open log file\n\n";
print LOGF "\n----------\n";
print LOGF sprintf("db_status started at %02d-%02d-%04d %02d:%02d:%02d\n",
$Tm->mon+1, $Tm->mday, $Tm->year+1900, $Tm->hour, $Tm->min, $Tm->sec );


The line that says 'db_status started...' does not get written for the hanging system because I usually 'kill -9' or 'Ctrl-C'
the process. I'd like to force a write after each section so I can see there the process is hanging.

Any help will be appreciated.

Thanks,
Mike

________________________________

Michael P. Vergara Be good and you will be lonesome
Oracle Database Administrator Mark Twain
(951) 914-2000 (Voice)
(951) 914-2990 (FAX)
www.guidant.com <http://www.guidant.com/>

Any views expressed herein are not necessarily those of Guidant Corporation.

Search Discussions

  • Stephan Harren at Nov 9, 2005 at 8:36 pm
    Close the Filehandle and re-open it after each line.

    HTH,

    Stephan
    Hello Everyone:

    I have a Perl script that connects to multiple Oracle databases. I
    have the script write some status information to
    a log file. There is one particular database that hangs in
    processing, and I don't know why. The log file does not seem
    to be written until the file is closed.

    I am wondering, is there a Perl command or technique that will force
    lines that are logically written to a log file to be
    physically written to that file?

    Here's my opening code:
    #
    #
    -------------------------------------------------------------------------
    # Open Log file
    #
    -------------------------------------------------------------------------
    my $logFileName = "${HomeDir}/work/monitor/output/logs/db_status.log";
    open( LOGF, ">>" . $logFileName ) or die "\nCannot open log file\n\n";
    print LOGF "\n----------\n";
    print LOGF sprintf("db_status started at %02d-%02d-%04d %02d:%02d:%02d\n",
    $Tm->mon+1, $Tm->mday, $Tm->year+1900, $Tm->hour,
    $Tm->min, $Tm->sec );
  • Chris Sarnowski at Nov 9, 2005 at 8:38 pm

    On Nov 9, 2005, at 3:24 PM, Vergara, Michael ((TEM)) wrote:

    Hello Everyone:

    I have a Perl script that connects to multiple Oracle databases. I
    have the script write some status information to
    a log file. There is one particular database that hangs in
    processing, and I don't know why. The log file does not seem
    to be written until the file is closed.

    I am wondering, is there a Perl command or technique that will
    force lines that are logically written to a log file to be
    physically written to that file?

    Here's my opening code:
    #
    #
    ----------------------------------------------------------------------
    ---
    # Open Log file
    #
    ----------------------------------------------------------------------
    ---
    my $logFileName = "${HomeDir}/work/monitor/output/logs/db_status.log";
    open( LOGF, ">>" . $logFileName ) or die "\nCannot open log file\n\n";
    print LOGF "\n----------\n";
    print LOGF sprintf("db_status started at %02d-%02d-%04d %02d:%02d:%
    02d\n",
    $Tm->mon+1, $Tm->mday, $Tm->year+1900, $Tm-
    hour, $Tm->min, $Tm->sec );

    The line that says 'db_status started...' does not get written for
    the hanging system because I usually 'kill -9' or 'Ctrl-C'
    the process. I'd like to force a write after each section so I can
    see there the process is hanging.

    Any help will be appreciated.

    Thanks,
    Mike
    This is a perl issue, not a DBI issue, but try

    autoflush LOGF 1;

    after you open LOGF.

    This should force a flush after every print statement. If it doesn't
    work I hope that at least it points you the right direction.
  • Rutherdale, Will at Nov 9, 2005 at 8:53 pm
    use IO::Handle;
    LOGF->autoflush( 1 );

    In the teach a man to fish spirit, look at the Perl Cookbook section 7.19.
    Also Programming Perl says a few things about this topic. You should have
    those books handy if you're writing much Perl code.

    That wasn't really a DBI question though.

    -Will


    -----Original Message-----
    From: Vergara, Michael (TEM)
    Sent: Wednesday 09 November 2005 15:25
    To: dbi-users@perl.org
    Subject: Logging Question


    Hello Everyone:

    I have a Perl script that connects to multiple Oracle databases. I have the
    script write some status information to
    a log file. There is one particular database that hangs in processing, and
    I don't know why. The log file does not seem
    to be written until the file is closed.

    I am wondering, is there a Perl command or technique that will force lines
    that are logically written to a log file to be
    physically written to that file?

    Here's my opening code:
    #
    # -------------------------------------------------------------------------
    # Open Log file
    # -------------------------------------------------------------------------
    my $logFileName = "${HomeDir}/work/monitor/output/logs/db_status.log";
    open( LOGF, ">>" . $logFileName ) or die "\nCannot open log file\n\n";
    print LOGF "\n----------\n";
    print LOGF sprintf("db_status started at %02d-%02d-%04d %02d:%02d:%02d\n",
    $Tm->mon+1, $Tm->mday, $Tm->year+1900, $Tm->hour,
    $Tm->min, $Tm->sec );


    The line that says 'db_status started...' does not get written for the
    hanging system because I usually 'kill -9' or 'Ctrl-C'
    the process. I'd like to force a write after each section so I can see
    there the process is hanging.

    Any help will be appreciated.

    Thanks,
    Mike

    _____

    Michael P. Vergara Be good and you will be lonesome
    Oracle Database Administrator Mark Twain
    (951) 914-2000 (Voice)
    (951) 914-2990 (FAX)
    <http://www.guidant.com/> www.guidant.com

    Any views expressed herein are not necessarily those of Guidant Corporation.




    - - - - - - - Appended by Scientific-Atlanta, Inc. - - - - - - -
    This e-mail and any attachments may contain information which is confidential, proprietary, privileged or otherwise protected by law. The information is solely intended for the named addressee (or a person responsible for delivering it to the addressee). If you are not the intended recipient of this message, you are not authorized to read, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer.
  • Vergara, Michael \(TEM\) at Nov 9, 2005 at 8:54 pm
    Ah! That works. Thanks, guys.

    And to the group, I kinda thought this was a Perl question, but since this is
    the only Perl group I'm on, I was hoping someone whould be able to help. If
    I have upset anyone, I apologize.

    Thanks,
    Mike

    ______________________________________________________________________________

    Michael P. Vergara Be good and you will be lonesome
    Oracle Database Administrator Mark Twain
    (951) 914-2000 (Voice)
    (951) 914-2990 (FAX)
    www.guidant.com

    Any views expressed herein are not necessarily those of Guidant Corporation.
  • Ronald J Kimball at Nov 9, 2005 at 9:38 pm
    This question is in the perlfaq, by the way.

    perldoc -q flush


    Ronald


    Vergara, Michael (TEM) wrote:
    Ah! That works. Thanks, guys.

    And to the group, I kinda thought this was a Perl question, but since this
    is
    the only Perl group I'm on, I was hoping someone whould be able to help.
    If
    I have upset anyone, I apologize.

    Thanks,
    Mike

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdbi-users @
categoriesperl
postedNov 9, '05 at 8:24p
activeNov 9, '05 at 9:38p
posts6
users5
websitedbi.perl.org

People

Translate

site design / logo © 2022 Grokbase