Hi, I'm very new to perl and am trying to use it to do some nifty stuff. I have a script that telnets to a given port on a machine, gets a number and then processes it into an array. After going through a host of machines it returns the whole thing with HTML. This works when run in command line but no values are shown if run from browser. I'm baffled, no errors in the logs to help me and diagnostics and -w don't help at all.. If anyone could take a look at this and tell me if there is some beginners error here I should slap myself for.
#!/usr/bin/perl BEGIN { $|=1; print "Content-type: text/html\n\n"; use CGI::Carp qw(fatalsToBrowser); } $kjarnavelar = "9"; $i = "0"; $rbports = "0"; $oraports = "0"; @host = ("x00802","x00803","x00804","x00902","x00903","x00904","xb0011 +2","xb00113","xb00114"); foreach $host (@host) { $rbport = `/usr/bin/telnet $host 1367 |egrep -v "Trying|Connec +|Escape"`; $rbarray[$i] = "$rbport"; $oracle = `/usr/bin/telnet $host 1371 |egrep -v "Trying|Connec +|Escape"`; $oraarray[$i] = "$oracle"; $oraports = $oraports+$oracle; $rbports = $rbports+$rbport; $i++; } print "<HTML>"; print "<TABLE BORDER=1>"; print "<TR><TD><B>Host</TD><TD><B>RB Ports Active</TD><TD><B>Oracle Po +rts Active</TD></TR>"; for($start=0;$start<=$kjarnavelar;$start++) { print "<TR><TD>$host[$start]</TD><TD>$rbarray[$start]</TD><TD> +$oraarray[$start]</TD></TR>"; } print "</TABLE>"; print "<TABLE BORDER=1>"; print "<TR><TD><B>Samtals RB Port</TD><TD><B>Samtals Oracle Port</TD>< +/TR>"; print "<TR><TD>$rbports</TD><TD>$oraports</TD></TR>"; print "</TABLE>"; print "</HTML>";

In reply to CGI script returns no values in browser but is ok on command line? by gudmo

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.