Monitor Server UP or Down and notify

#!/bin/bash
 ## Global variables
 TO=admin@example.com
 CC=admin@example.com
 FROM="Your Server Remote Monitor <automation@example.com>"
 user=gmailuser
 pass=gmailuserpass
 SMTP=smtp.gmail.com:587
 nitstatus=/tmp/nit

###### Check line up or down
 ping -c3 example.com ; [ $? == 0 ] && checkstatus=up || status is checkstatus=down ; clear ; echo status is  $checkstatus |tail -1

if [[  ! -f $nitstatus ]];
 then
 echo up > $nitstatus
 fi
 oldstatus=`cat /tmp/nit`
 echo old status is $oldstatus
 echo $checkstatus
 if [[ $checkstatus == "up" ]]
 then
 newstatus=up
 elif [[ $checkstatus == "down" ]]
 then
 newstatus=down
 fi
 ###### Email notification ###

echo new status is $newstatus

if
 [[ $oldstatus != $newstatus ]]
 then

echo "Your Server server is $newstatus"
 echo $newstatus > $nitstatus
 if [[ $newstatus == "down" ]]
 then
 echo sending email for down
 /neuralit/scripts/sendEmail.pl -f "$FROM" -t "$TO"  -s  "$SMTP" -xu "$user" -xp "$pass"  -u "Your Server Server is Down" -m "
 Your Server server is down on `date +%T`"
 elif [[ $newstatus == "up" ]]
 then
 echo sending email for up
 /neuralit/scripts/sendEmail.pl -f "$FROM" -t "$TO"  -s  "$SMTP" -xu "$user" -xp "$pass"  -u "Your Server Server is Up" -m "
 Your Server server is up on `date +%T`"
 fi

else
 echo no change
 fi