Hello all,
I was trying to write a cgi-script that displays the results of a ping
against a host that is passed to the cgi-script. The first time, I used what
I might term the "brute force approach", which didn't work and then, I used
Net::Ping, which worked. However I am really curious as to why the first
approach didn't work....
For each script below, the URL that would call the script [btw, all
resemblances of these script structures to a certain CGI scripting example
from 'Learning Perl' are entirely coincidental :) ] was:
http://<IP-Address>/cgi-bin/myping?Node=Atlantis
Working script
--------------
#!/usr/local/bin/perl -w
use CGI qw(param);
use Net::Ping;
print<<Section1;
Content-type: text/html
<HTML>
<HEAD>
<TITLE>Result of "Ping" Operation</TITLE>
</HEAD>
<BODY>
Section1
$pnode = param("Node");
$p = Net::Ping->new();
if($p->ping($pnode)) { print "\n\n $pnode is alive\n"; }
else { print "\n\n$pnode is not reachable \n\n"; }
$p->close();
print<<Section2;
</BODY>
</HTML>
Section2
--> What I don't like about the above script is that I cannot see the
results of each individual ping, which was I was hoping to see using the
(non-working) script, below:
Non-working script
------------------
#!/usr/local/bin/perl -w
use CGI qw(param);
use Net::Ping;
print<<Section1;
Content-type: text/html
<HTML>
<HEAD>
<TITLE>Result of "Ping" Operation</TITLE>
</HEAD>
<BODY>
Section1
$pnode = param("Node");
system "(/usr/sbin/ping -sRv -I 1 $pnode 64 5)>/tmp/pingresults.$$";
# *** I could never see /tmp/pingresults.$$ created, above, when the script
was called.
# However when I executed what was within the system call from the shell
directly, there were no problems, obviously !!!
open(INFILE,"/tmp/pingresults.$$");
while(<INFILE>) {
print;
}
close(INFILE);
print<<Section2;
</BODY>
</HTML>
Section2
#