Server ping?

Hey guys/gals,
I need help getting this to work, my debugger gives me

"Can't locate object method "new" via package "Net::Ping" at script line 42.

Can you help me figure this out? Below is what I have so far not including all the variables.

Thanks a bunch!
William


## Ping the server and send the email if needed. ##
use Net::Ping;
$p = Net::Ping->new($proto, $timeout, $bytes);
$p->ping($serverip, $timeout);
$p->close();

if ($p eq "1") {
      print "I'm still tickin'\n";
}
elsif ($p eq "0") {
    open (MAIL, "|$mail_prog -t");
    print MAIL "To: $email\n";
    print MAIL "Reply-to: Your Server\n";
    print MAIL "From: Your Server\n";
    print MAIL "Subject: Help Me!\n";
    print MAIL "\n\n";
    print MAIL "This is your server at \$serverip. Something is wrong! Help Me!\n" ;
    print MAIL "\n\n";
    close (MAIL);
}
exit;

wglennAsked:
Who is Participating?
 
guadalupeConnect With a Mentor Commented:
What about a work around.  This code will directly use the OS ping.  You just might want to check your version of ping (as it might be different from mine) to see if the "number of pings" switch is the same.

In windows just type "ping"
 at a dos prompt, in Unix type "ping -h" at a prompt...
0
 
marko020397Commented:
It looks like Net::Ping package does not work. What do you have
in $proto, $timeout and $bytes variables. Did you fill them with
appropriate values. If you don't know what these variable are
for then delete them. The program will work without them too.
0
 
guadalupeCommented:
Sorry I forgot the code!!!!!!

#!/usr/local/bin/perl

######################Windows version
#n set number of pings -n 4 means four pings
$info = `ping -n 4 www.uol.com.ar`;

if ($info =~ /bytes/i)
{
      print "Alive!\n";
}
else
{
      print "Dead.\n";
}


###########Unix
#c sets number of pings
$info = `ping -c 4 www.uol.com.ar`;

if ($info =~ /bytes/i)
{
      print "Alive!\n";
}
else
{
      print "Dead.\n";
}
0
 
wglennAuthor Commented:
Thanks for the great help!
0
All Courses

From novice to tech pro — start learning today.