FAQ
Hello all,

I have a script that is checking a service to see if its running and
that its log file does not contain two error message to confirm that it
has not died. However the subrutine is just saying its up when I have
put the error message in the last line of the log to make sure it sees
that its down. Please have a look at the code snipit and any help would
be great.

Thanks,

Tim

sub grepstring {
open LOG, "tail gw_20050105.log |", or die "Log file not found $!";
while (<LOG>) {
$newlog = <LOG>;
if ($newlog =~ /^Read failed on socket/ || /^EFIXException::/) {
exit $exit_codes{'CRITICAL'};
print "Log entry can not be found GW down!\n";
} else {
print "GW is UP!\n";
exit $exit_codes{'OK'};
}

}
}

Search Discussions

  • JupiterHost.Net at Jan 13, 2005 at 3:38 pm

    Tim Wolak wrote:

    Hello all,

    I have a script that is checking a service to see if its running and
    that its log file does not contain two error message to confirm that it
    has not died. However the subrutine is just saying its up when I have
    put the error message in the last line of the log to make sure it sees
    that its down. Please have a look at the code snipit and any help would
    be great.
    use strict;
    use warnings;

    always always always!
    Thanks,

    Tim

    sub grepstring {
    open LOG, "tail gw_20050105.log |", or die "Log file not found $!";
    It wasn't found? are you sure, what if it found but the permisions won't
    allow it to be read, what if it was locked? Let $! tell you the exact
    reason :)

    Why are you piping tail's output to LOG?

    Why not

    open LOG, 'gw_20050105.log' or die "open qw_200050105 failed: $!";
    while (<LOG>) {
    $newlog = <LOG>;
    my $newlog would be better so its in scope, just using $_ would be even
    better :)
    if ($newlog =~ /^Read failed on socket/ || /^EFIXException::/) {
    exit $exit_codes{'CRITICAL'};
    print "Log entry can not be found GW down!\n";
    This will never get printed because its already exited

    } else {
    print "GW is UP!\n";
    exit $exit_codes{'OK'};
    }
    } }
    How about this:

    open LOG, 'gw_20050105.log' or die "open qw_200050105 failed: $!";
    while(<LOG>) {
    if(/^Read failed on socket/ || /^EFIXException::/) {
    print "Log entry can not be found GW down!\n";
    exit $exit_codes{CRITICAL};
    } else {
    print "GW is UP!\n";
    exit $exit_codes{OK};
    }
    }
    close LOG;

    HTH :)

    Lee.M - JupiterHost.Net
  • Ing. Branislav Gerzo at Jan 13, 2005 at 3:47 pm
    Tim Wolak [TW], on Thursday, January 13, 2005 at 09:15 (-0600) wrote
    about:

    TW> if ($newlog =~ /^Read failed on socket/ || /^EFIXException::/) {

    for me it seems, this line is bad, when you rewrite it to:

    if ($newlog =~ /^(Read failed on socket|EFIXException::)/) {

    it works ?

    --

    ...m8s, cu l8r, Brano.

    ["The sun is in the east even though the day is done" -Pink Floyd]
  • Maxipoint Rep Office at Jan 13, 2005 at 4:11 pm
    how upload files with Perl using MySQL database?
    i wish that file be uploaded to the one folder on the server and the path og
    image must be added into MySQL database column..
  • Maxipoint Rep Office at Jan 16, 2005 at 10:38 pm
    Have someone idea or url how create Triple Combo Box with Perl?

    something like here:
    http://javascriptkit.com/script/script2/triplecombo.shtml

    but not redirection at the end, i need only data submision after user select
    combination..
  • Charles K. Clarkson at Jan 17, 2005 at 12:04 am
    Maxipoint Rep Office wrote:

    : Have someone idea or url how create Triple Combo Box with Perl?
    :
    : something like here:
    : http://javascriptkit.com/script/script2/triplecombo.shtml
    :
    : but not redirection at the end, i need only data submision
    : after user select combination..


    It won't look the same in perl. In JavaScript all the
    info for every combination is sent with the page. Each
    time you select a different value from the first box, the
    values of the second box change. This is all done through
    JavaScript, using the clients browser.

    To replicate this is only perl, the user would select
    a value from the first menu and than submit that to the
    server, the server would then return the values for the
    second set. Each time, the server sends a new page
    rewriting everything instead of just the combo box
    controls.

    The user also has to send the information selection
    from each combo with a button if you want to completely
    eliminate all JavaScript. If you want the selection sent
    as the choice is selected, you need JavaScript. So why
    not use the JavaScript triple combo?

    To sum up, yes, you can get triple box functionality
    with perl, but the user won't experience the same feel as
    she does with the JavaScript version. The perl version
    would require at least two trips to the server before
    data selection.


    HTH,

    Charles K. Clarkson
    --
    Mobile Homes Specialist
    254 968-8328
  • John W. Krahn at Jan 13, 2005 at 11:39 pm

    Tim Wolak wrote:
    Hello all, Hello,
    I have a script that is checking a service to see if its running and
    that its log file does not contain two error message to confirm that it
    has not died. However the subrutine is just saying its up when I have
    put the error message in the last line of the log to make sure it sees
    that its down. Please have a look at the code snipit and any help would
    be great.


    sub grepstring {
    open LOG, "tail gw_20050105.log |", or die "Log file not found $!";
    Since you are using a piped open you should also close() the filehandle and
    verify that it closed correctly.

    perldoc -f close
    perldoc perlopentut


    You should probably also use a lexically scoped filehandle.

    while (<LOG>) {
    $newlog = <LOG>;
    You putting the first line into $_ and the second line into $newlog so you are
    only examining the contents of every second line.

    if ($newlog =~ /^Read failed on socket/ || /^EFIXException::/) {
    exit $exit_codes{'CRITICAL'};
    print "Log entry can not be found GW down!\n";
    } else {
    print "GW is UP!\n";
    exit $exit_codes{'OK'};
    }
    } }

    John
    --
    use Perl;
    program
    fulfillment
  • John W. Krahn at Jan 13, 2005 at 11:46 pm

    John W. Krahn wrote:
    Tim Wolak wrote:
    I have a script that is checking a service to see if its running and
    that its log file does not contain two error message to confirm that
    it has not died. However the subrutine is just saying its up when I
    have put the error message in the last line of the log to make sure it
    sees that its down. Please have a look at the code snipit and any
    help would be great.

    sub grepstring {
    open LOG, "tail gw_20050105.log |", or die "Log file not found $!";
    Since you are using a piped open you should also close() the filehandle
    and verify that it closed correctly.

    perldoc -f close
    perldoc perlopentut

    You should probably also use a lexically scoped filehandle.
    while (<LOG>) {
    $newlog = <LOG>;
    You putting the first line into $_ and the second line into $newlog so
    you are only examining the contents of every second line.
    if ($newlog =~ /^Read failed on socket/ || /^EFIXException::/) {
    Correction, you are examining every odd numbered line for /^EFIXException::/
    and every even numbered line for /^Read failed on socket/.

    exit $exit_codes{'CRITICAL'};
    print "Log entry can not be found GW down!\n";
    } else {
    print "GW is UP!\n";
    exit $exit_codes{'OK'};
    }
    } }

    John
    --
    use Perl;
    program
    fulfillment
  • Michael Kraus at Jan 16, 2005 at 11:57 pm
    You don't. You create it with HTML and JavaScript. You use perl to read
    the select boxes values.

    It's simply that Perl is used server-side, not client-side. Perl can be
    used to generate the HTML (and javascript if needed).

    Javascript is a client-side technology. The two languages don't directly
    compete with each other, but can be used co-operatively.

    Perl packages of interest to you would be: CGI, HTML::Template,
    CGI::FormBuilder and/or CGI::Untaint

    Regards,


    Michael S. E. Kraus
    B. Info. Tech. (CQU), Dip. Business (Computing)
    Software Developer
    Wild Technology Pty Ltd
    _______________________________
    ABN 98 091 470 692
    Level 4 Tiara, 306/9 Crystal Street, Waterloo NSW 2017, Australia
    Telephone 1300-13-9453 | Facsimile 1300-88-9453
    http://www.wildtechnology.net

    The information contained in this email message and any attachments may
    be confidential information and may also be the subject of client legal
    - legal professional privilege. If you are not the intended recipient,
    any use, interference with, disclosure or copying of this material is
    unauthorised and prohibited. This email and any attachments are also
    subject to copyright. No part of them may be reproduced, adapted or
    transmitted without the written permission of the copyright owner. If
    you have received this email in error, please immediately advise the
    sender by return email and delete the message from your system.
    -----Original Message-----
    From: Maxipoint Rep Office
    Sent: Monday, 17 January 2005 9:39 AM
    To: beginners@perl.org
    Subject: Spam:Triple Combo Box with Perl?


    Have someone idea or url how create Triple Combo Box with Perl?

    something like here:
    http://javascriptkit.com/script/script2/triplecombo.shtml

    but not redirection at the end, i need only data submision
    after user select combination..


    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org For
    additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>


    --------------------------------------------------------------------------------

    Wild Technology Pty Ltd , ABN 98 091 470 692
    Sales - Ground Floor, 265/8 Lachlan Street, Waterloo NSW 2017
    Admin - Level 4 Tiara, 306/9 Crystal Street, Waterloo NSW 2017
    Telephone 1300-13-9453 | Facsimile 1300-88-9453
    http://www.wildtechnology.net
    DISCLAIMER & CONFIDENTIALITY NOTICE: The information contained in this email message and any attachments may be confidential information and may also be the subject of client legal - legal professional privilege. If you are not the intended recipient, any use, interference with, disclosure or copying of this material is unauthorised and prohibited. This email and any attachments are also subject to copyright. No part of them may be reproduced, adapted or transmitted without the written permission of the copyright owner. If you have received this email in error, please immediately advise the sender by return email and delete the message from your system.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedJan 13, '05 at 3:15p
activeJan 17, '05 at 12:04a
posts9
users7
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase