Boxerman Posted August 5, 2013 Share Posted August 5, 2013 (edited) 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@mail.com"; $fromemail = "ALERTER@mail.com"; $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 Edited August 5, 2013 by Boxerman Quote 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 Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/280835-ping-script-gone-wrong/#findComment-1443491 Share on other sites More sharing options...
Solution .josh Posted August 5, 2013 Solution 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. Quote Link to comment https://forums.phpfreaks.com/topic/280835-ping-script-gone-wrong/#findComment-1443492 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.