printing output of ping command -- New question at bottom.

2005-02-23 Thread Tyson Sommer
 

> -Original Message-
> From: Chris Devers [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, February 23, 2005 10:14 AM
> To: TapasranjanMohapatra
> Cc: Perl Beginners List
> Subject: Re: printing output of ping command
> 
> On Wed, 23 Feb 2005, TapasranjanMohapatra wrote:
> 
> > I have a script as follows
> > 
> > my $host = shift;
> > my $count = shift;
> > my $result = `ping -c $count $host`;
> > if($result =~ m/$count packets transmitted, $count packets 
> received/)
> > {
> >  $success = 1;
> > }
> > print "$result\n";
> > 
>  
> Is there a reason you're using backticks instead of just 
> doing this all 
> in Perl directly?
> 
> 
> 
> This sidesteps having to make a regex to parse the results, 
> which will 
> work inconsistently (that is, not at all) with other versions 
> of `ping`. 
> 
> This approach should be more flexible in general; the 
> documentation at 
> the URL above should give you the tools you need to do what 
> you want in 
> a reliable, portable way.


This might be a question for beginners-cgi, but since it was mentioned
here...

I tried to use Net::Ping in a CGI script and it said I didn't have
permissions to run ping. I can execute the section of the CGI script with
the call to Net::Ping just fine from the cmd line as a regular user. If I
use backticks instead, the script runs just fine via the CGI. Any
suggestions? I'm still somewhat novice on a *nix box, so I don't know what
to change to allow ping to be run from Net::Ping via the CGI interface (via
Apache).

Assume warnings, strictures, and that a new CGI has been called (everything
else in the script works fine), blah, blah:


my $pinger = Net::Ping->new("icmp") || die; 
my $device = $q->param('device');

if( $pinger->ping($host,2) ){
print "$host is online\n";
}
else{
print "$host is offline\n";
}


This gets me an error in my browser saying I don't have permission to run
ping (yes, using CGI::Carp... As well for troubleshooting).


Thanks!
Tyson



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: printing output of ping command -- New question at bottom.

2005-02-23 Thread Chris Devers
On Wed, 23 Feb 2005, Tyson Sommer wrote:

> This might be a question for beginners-cgi, but since it was mentioned
> here...

Sounds like it, but oh well.

This doesn't really fix your problem so much as your error handling, but 
why aren't you catching the reason your script dies?

Instead of

my $pinger = Net::Ping->new("icmp") || die; 

Why not use 

my $pinger = Net::Ping->new("icmp") || die "Can't make pinger: $!"; 

This might at least give you a more descriptive error message...

Also, are you having CGI::Carp use fatalsToBrowser for testing?


-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: printing output of ping command -- New question at bottom.

2005-02-23 Thread John W. Krahn
Tyson Sommer wrote:
This might be a question for beginners-cgi, but since it was mentioned
here...
I tried to use Net::Ping in a CGI script and it said I didn't have
permissions to run ping. I can execute the section of the CGI script with
the call to Net::Ping just fine from the cmd line as a regular user. If I
use backticks instead, the script runs just fine via the CGI. Any
suggestions? I'm still somewhat novice on a *nix box, so I don't know what
to change to allow ping to be run from Net::Ping via the CGI interface (via
Apache).
Assume warnings, strictures, and that a new CGI has been called (everything
else in the script works fine), blah, blah:
my $pinger = Net::Ping->new("icmp") || die; 
my $device = $q->param('device');

if( $pinger->ping($host,2) ){
print "$host is online\n";
}
else{
print "$host is offline\n";
}
This gets me an error in my browser saying I don't have permission to run
ping (yes, using CGI::Carp... As well for troubleshooting).

perldoc Net::Ping
[snip]
   If the "icmp" protocol is specified, the ping() method sends an icmp
   echo message to the remote host, which is what the UNIX ping program
   does.  If the echoed message is received from the remote host and the
   echoed information is correct, the remote host is considered reachable.
   Specifying the "icmp" protocol requires that the program be run as root
   or that the program be setuid to root.
Your web server does not run as root so you have to use either TCP or UDP
instead of ICMP.

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: printing output of ping command -- New question at bottom.

2005-02-24 Thread Tyson Sommer
 

> -Original Message-
> From: Chris Devers [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, February 23, 2005 1:18 PM
> To: Tyson Sommer
> Cc: 'Perl Beginners List'
> Subject: Re: printing output of ping command -- New question 
> at bottom.
> 
> On Wed, 23 Feb 2005, Tyson Sommer wrote:
> 
> > This might be a question for beginners-cgi, but since it 
> was mentioned
> > here...
> 
> Sounds like it, but oh well.
> 
> This doesn't really fix your problem so much as your error 
> handling, but 
> why aren't you catching the reason your script dies?
> 
> Instead of
> 
> my $pinger = Net::Ping->new("icmp") || die; 
> 
> Why not use 
> 
> my $pinger = Net::Ping->new("icmp") || die "Can't make 
> pinger: $!"; 

I do that. I just was being lazy in typing here (thought that part was
inconsequential).



> This might at least give you a more descriptive error message...
> 
> Also, are you having CGI::Carp use fatalsToBrowser for testing?


Yes. Thus the error message that I'm seeing in my browser.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: printing output of ping command -- New question at bottom.

2005-02-24 Thread Tyson Sommer
 

> -Original Message-
> From: John W. Krahn [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, February 23, 2005 2:50 PM
> To: Perl Beginners
> Subject: Re: printing output of ping command -- New question 
> at bottom.
> 
> Tyson Sommer wrote:
> > 
> > This might be a question for beginners-cgi, but since it 
> was mentioned
> > here...
> > 
> > I tried to use Net::Ping in a CGI script and it said I didn't have
> > permissions to run ping. I can execute the section of the 
> CGI script with
> > the call to Net::Ping just fine from the cmd line as a 
> regular user. If I
> > use backticks instead, the script runs just fine via the CGI. Any
> > suggestions? I'm still somewhat novice on a *nix box, so I 
> don't know what
> > to change to allow ping to be run from Net::Ping via the 
> CGI interface (via
> > Apache).
> > 
> > Assume warnings, strictures, and that a new CGI has been 
> called (everything
> > else in the script works fine), blah, blah:
> > 
> > my $pinger = Net::Ping->new("icmp") || die; 
> > my $device = $q->param('device');
> > 
> > if( $pinger->ping($host,2) ){
> > print "$host is online\n";
> > }
> > else{
> > print "$host is offline\n";
> > }
> > 
> > This gets me an error in my browser saying I don't have 
> permission to run
> > ping (yes, using CGI::Carp... As well for troubleshooting).
> 
> 
> perldoc Net::Ping
> [snip]
> If the "icmp" protocol is specified, the ping() 
> method sends an icmp
> echo message to the remote host, which is what the 
> UNIX ping program
> does.  If the echoed message is received from the 
> remote host and the
> echoed information is correct, the remote host is 
> considered reachable.
> Specifying the "icmp" protocol requires that the 
> program be run as root
> or that the program be setuid to root.
> 
> 
> Your web server does not run as root so you have to use 
> either TCP or UDP
> instead of ICMP.



That worked.

Note to self: RTFM...B (Better)


Thanks,
Tyson



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>