Hello,
Your working script is *definitely* the way you want to go... its generally
a no-no to ever give user 'nobody' (e.g. web server) access to your shell
(which is what is happening with the system() call).

In fact, I wouldn't be surprised if the sys admin. doesn't allow user
'nobody'
to do much of anything :)

./dave

> -----Original Message-----
> From: Mohan Kompella [mailto:[EMAIL PROTECTED]]
> Sent: Friday, June 01, 2001 4:42 PM
> To: [EMAIL PROTECTED]
> Subject: perl ping script using cgi
>
>
> 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
> #
>

Reply via email to