Boxerman Posted August 5, 2013 Share Posted August 5, 2013 Hi guys, wacking together a ping script with alert however, i cant seem to get it to work no matter what the IP is it says UP! <? $hosts = array( array ( "hostdescription" => "B01","hostaddress" => "REALIPHIDDEN" ), array ( "hostdescription" => "B02", "hostaddress" => "REALIPHIDDEN" ) ); $toemail = "[email protected]"; $fromemail = "[email protected]"; $pingcount = 1; foreach ($hosts as $host){ $hostdescription = $host["hostdescription"]; $hostaddress = $host["hostaddress"]; exec("ping -c $pingcount -w $pingcount $hostaddress", $pingoutput, $Spingstatuscode); if($pingstatuscode == 0){ echo("$hostdescription ($hostaddress) is Up <BR>"); }else{ echo("$hostdescription ($hostaddress) is Down <BR>"); mail($toemail,"Host Down","$hostdescription ($hostaddress) is Down!","From: $fromemail"); } } ?> Can a second set of eyes see where im going wrong? Thanks, B-Man Link to comment https://forums.phpfreaks.com/topic/280835-ping-script-gone-wrong/ Share on other sites More sharing options...
Boxerman Posted August 5, 2013 Author Share Posted August 5, 2013 MORE INFO: This is pinging from Linux to a windows box Link to comment https://forums.phpfreaks.com/topic/280835-ping-script-gone-wrong/#findComment-1443489 Share on other sites More sharing options...
.josh Posted August 5, 2013 Share Posted August 5, 2013 $Spingstatuscode != $pingstatuscode Link to comment https://forums.phpfreaks.com/topic/280835-ping-script-gone-wrong/#findComment-1443491 Share on other sites More sharing options...
.josh Posted August 5, 2013 Share Posted August 5, 2013 also fyi == is a loose comparison, so anything that would evaluate to 0 (e.g boolean false) will make that condition true. If you want to be more accurate about evaluating the return codes, use === instead. Link to comment https://forums.phpfreaks.com/topic/280835-ping-script-gone-wrong/#findComment-1443492 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.