Using perl to check services

Discussion in 'Perl' started by Jason Miles, Apr 6, 2004.

  1. Jason Miles

    Jason Miles Guest

    Hi,

    I wrote this little script to check to see if our Lotus Notes servers are
    running, and from the command line it works fine if I type perl
    notescheck.pl

    When I invoke the script from a web page I get an error:
    Internal Server Error
    The server encountered an internal error or misconfiguration and was unable
    to complete your request.

    Please contact the server administrator, and inform them of
    the time the error occurred, and anything you might have done that may have
    caused the error.

    More information about this error may be available in the server error log.



    Here is the script:

    #!/usr/bin/perl -w
    #use strict;
    use IO::Socket;

    $hostName = notesserver;
    my $host = shift || $hostName;
    my $port = shift || 25;
    my $sock = new
    IO::Socket::INET(PeerAddr=>$host,PeerPort=>$port,Proto=>'tcp');
    if($sock)
    {
    print "<script>
    alert(\"Server notesserver is running...\");
    history.back();
    </script>";
    exit;
    }
    else
    {
    print "<script>
    alert(\"Server notesserver appears to be down...\");
    history.back();
    </script>";
    exit;
    }
    close $sock or die "close: $!";



    When I run the script from the console (perl notescheck.pl) I get the
    following:

    <script>
    alert("Server RSLNM02 is running...");
    history.back();
    </script>[root@rts cgi-bin]#
    ....which tells me the script is running fine.

    Heres the code from the web page:

    <form action="/cgi-bin/notescheck.pl" method="post">
    <input type="submit">

    Can anyone tell me why this doesn't work?

    Thanks,
    Jason
     
    Jason Miles, Apr 6, 2004
    #1
    1. Advertising

  2. Jason Miles

    Jim Gibson Guest

    In article <qVAcc.19651$>, Jason Miles
    <> wrote:

    > Hi,
    >
    > I wrote this little script to check to see if our Lotus Notes servers are
    > running, and from the command line it works fine if I type perl
    > notescheck.pl
    >
    > When I invoke the script from a web page I get an error:


    [server error snipped]

    >
    > Here is the script:
    >
    > #!/usr/bin/perl -w
    > #use strict;
    > use IO::Socket;
    >
    > $hostName = notesserver;

    ^^^^^^^^^^^ bareword?

    > my $host = shift || $hostName;
    > my $port = shift || 25;
    > my $sock = new
    > IO::Socket::INET(PeerAddr=>$host,PeerPort=>$port,Proto=>'tcp');
    > if($sock)
    > {
    > print "<script>
    > alert(\"Server notesserver is running...\");
    > history.back();
    > </script>";
    > exit;
    > }
    > else
    > {
    > print "<script>
    > alert(\"Server notesserver appears to be down...\");
    > history.back();
    > </script>";
    > exit;
    > }
    > close $sock or die "close: $!";
    >


    Is this the code you ran? It contains a bare-word 'noteserver', which
    should probably be a variable or a string, but you do not show how it
    gets the value 'RSLNM02'. You would have noticed this if you had left
    the 'use strict;' line uncommented. Please do not ask people to find
    problems that the compiler can easily find.

    What is the error message in the server log? (You did look for the
    error message in the server log, didn't you?)

    Try

    perldoc -q 500

    for more help, particularly about the proper newsgroup for posting
    about web server questions (your Perl program looks OK, except for the
    noted error).

    Finally, this newsgroup is defunct. Try comp.lang.perl.misc in the
    future for Perl questions.
     
    Jim Gibson, Apr 6, 2004
    #2
    1. Advertising

  3. Jason Miles

    James T Guest

    On Tue, 06 Apr 2004 13:27:26 -0700, Jim Gibson wrote:

    > In article <qVAcc.19651$>, Jason Miles
    > <> wrote:
    >
    >> Hi,
    >>
    >> I wrote this little script to check to see if our Lotus Notes servers
    >> are running, and from the command line it works fine if I type perl
    >> notescheck.pl
    >>
    >> When I invoke the script from a web page I get an error:

    >
    > [server error snipped]
    >
    >
    >> Here is the script:
    >>
    >> #!/usr/bin/perl -w
    >> #use strict;
    >> use IO::Socket;
    >>
    >> $hostName = notesserver;

    > ^^^^^^^^^^^ bareword?
    >
    >> my $host = shift || $hostName;
    >> my $port = shift || 25;
    >> my $sock = new
    >> IO::Socket::INET(PeerAddr=>$host,PeerPort=>$port,Proto=>'tcp');
    >> if($sock)
    >> {
    >> print "<script>
    >> alert(\"Server notesserver is running...\");
    >> history.back();
    >> </script>";
    >> exit;
    >> }
    >> else
    >> {
    >> print "<script>
    >> alert(\"Server notesserver appears to be down...\");
    >> history.back();
    >> </script>";
    >> exit;
    >> }
    >> close $sock or die "close: $!";
    >>
    >>

    > Is this the code you ran? It contains a bare-word 'noteserver', which
    > should probably be a variable or a string, but you do not show how it
    > gets the value 'RSLNM02'. You would have noticed this if you had left
    > the 'use strict;' line uncommented. Please do not ask people to find
    > problems that the compiler can easily find.
    >
    > What is the error message in the server log? (You did look for the error
    > message in the server log, didn't you?)
    >
    > Try
    >
    > perldoc -q 500
    >
    > for more help, particularly about the proper newsgroup for posting about
    > web server questions (your Perl program looks OK, except for the noted
    > error).
    >
    > Finally, this newsgroup is defunct. Try comp.lang.perl.misc in the
    > future for Perl questions.


    This may be a stupid question, other then the bare word, isn't this script
    also missing the content type, so the output is interpreted by the browser
    as a a web page?
     
    James T, Apr 7, 2004
    #3
  4. Jason Miles

    Jason Miles Guest

    Yes, that's exactly what the problem was. Thanks for your replies...

    "James T" <turajb@_NOSPAM_hoflink.com> wrote in message
    news:pan.2004.04.07.03.28.06.765573@_NOSPAM_hoflink.com...
    > On Tue, 06 Apr 2004 13:27:26 -0700, Jim Gibson wrote:
    >
    > > In article <qVAcc.19651$>, Jason Miles
    > > <> wrote:
    > >
    > >> Hi,
    > >>
    > >> I wrote this little script to check to see if our Lotus Notes servers
    > >> are running, and from the command line it works fine if I type perl
    > >> notescheck.pl
    > >>
    > >> When I invoke the script from a web page I get an error:

    > >
    > > [server error snipped]
    > >
    > >
    > >> Here is the script:
    > >>
    > >> #!/usr/bin/perl -w
    > >> #use strict;
    > >> use IO::Socket;
    > >>
    > >> $hostName = notesserver;

    > > ^^^^^^^^^^^ bareword?
    > >
    > >> my $host = shift || $hostName;
    > >> my $port = shift || 25;
    > >> my $sock = new
    > >> IO::Socket::INET(PeerAddr=>$host,PeerPort=>$port,Proto=>'tcp');
    > >> if($sock)
    > >> {
    > >> print "<script>
    > >> alert(\"Server notesserver is running...\");
    > >> history.back();
    > >> </script>";
    > >> exit;
    > >> }
    > >> else
    > >> {
    > >> print "<script>
    > >> alert(\"Server notesserver appears to be down...\");
    > >> history.back();
    > >> </script>";
    > >> exit;
    > >> }
    > >> close $sock or die "close: $!";
    > >>
    > >>

    > > Is this the code you ran? It contains a bare-word 'noteserver', which
    > > should probably be a variable or a string, but you do not show how it
    > > gets the value 'RSLNM02'. You would have noticed this if you had left
    > > the 'use strict;' line uncommented. Please do not ask people to find
    > > problems that the compiler can easily find.
    > >
    > > What is the error message in the server log? (You did look for the error
    > > message in the server log, didn't you?)
    > >
    > > Try
    > >
    > > perldoc -q 500
    > >
    > > for more help, particularly about the proper newsgroup for posting about
    > > web server questions (your Perl program looks OK, except for the noted
    > > error).
    > >
    > > Finally, this newsgroup is defunct. Try comp.lang.perl.misc in the
    > > future for Perl questions.

    >
    > This may be a stupid question, other then the bare word, isn't this script
    > also missing the content type, so the output is interpreted by the browser
    > as a a web page?
     
    Jason Miles, Apr 7, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nick
    Replies:
    1
    Views:
    6,268
    Alvin Bruney - ASP.NET MVP
    Sep 12, 2005
  2. Anup
    Replies:
    1
    Views:
    2,828
    Mark Rae
    May 9, 2006
  3. Replies:
    1
    Views:
    3,442
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Dec 24, 2006
  4. Replies:
    0
    Views:
    158
  5. prati
    Replies:
    0
    Views:
    501
    prati
    Oct 27, 2012
Loading...

Share This Page