Script to ping test for host and alert/notification with display while running from cronjob also

export DISPLAY=:0.0
export XAUTHORITY=/home/user/.Xauthority
HOSTS="xx.xx.xx.xx xx.xx.xx.xx"
for myHost in $HOSTS
  count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
  if [ $count -eq 0 ]; then
    # 100% failed 
    notify-send "Host : $myHost is down (ping failed) at $(date)"
    zenity --warning --text="Host : $myHost is down (ping failed) at $(date)" --title="Ping Failed!"

NOTE : make sure you change the XAUTHORITY path with proper user name

exports are more important when you call the script from cron, other wise you wont alert/notification box in GUI