// a utility designed to send out an email if pingtimes
// on a target server exceed desired delay times
// system call to ping desired host, use IP address
$rawPing = `ping -c 10 xxx.xxx.xxx.xxx`;
// extract average time from string
eregi("mdev = (.*)ms", $rawPing, $return);
// grab desired first element of array and assign to $string
$strPing = $return[0];
// echo to screen for debugging :)
echo("<br> raw string =" . $strPing);
// extract average delay from string
$delaySeconds = substr($strPing, 13, 5);
// convert to conventional milliseconds
$delayMilliseconds = $delaySeconds * 1000;
// echo to screen for debugging :)
echo("<br> formatted string =" . $delayMilliseconds);
// send out warning email if desired pingtime exceeded
if ($delayMilliseconds > 200) {
mail ("user@domain.com", "we've got a delay here
of $delayMilliseconds milliseconds", "");
}
?>
Demian Turner wrote :719
This script has been tailored to what "ping -c" returns on a Redhat 7.1 Linux installation. You may need to customise the string parsing to your particular system. The script is explained in more detail at http://www.phpkitchen.com/article.php?story=2001070313581898