|
Posted by Juan Pablo Herrera on 08/21/05 09:34
On 8/21/05, Jasper Bryant-Greene <jasper@bryant-greene.name> wrote:
> Juan Pablo Herrera wrote:
> > Thanks Jasper,
> > well, i need make a explode of results of the ping. The idea is check
> > a host and when the host don´ t response send a email.
> > I don't explode the result of the ping.
>
> If it was me, I'd try opening a socket connection to the host instead,
> and check to see if you can connect or not. Whether or not that is
> suitable to your application I don't know...
>
> Jasper
>
Hi!
I did following script:
<?php
// Exec a ping
exec('ping -c 5 192.168.236.3',$result);
// Take result from icmp seq = 2
$icmp = strpos($result[2], 'time=');
$icmp = $icmp + 5;
$fin = strpos($result[2], 'ms');
// This is my end
$fin = $fin - $icmp;
// I take only the ms time
$text = substr($result[2],$icmp,$fin);
// Strip whitespace
$ms = trim($text);
if (!is_numeric($ms)) {
$a = 'myemail@host.com';
$asunto = "Servidor Caido";
$mensaje = "Posible caida del servidor. No responde PING.";
mail($a, $asunto, $mensaje);
}
?>
It's very simple, but i think that is working. I will add other options.
JP
[Back to original message]
|