help with bash script!
im am working on this script to make sure my server will stay online, so i made this script..
HOSTS="192.168.138.155"
COUNT=4
pingtest(){
for myhost in "$@"
do
ping -c "$COUNT" "$myhost" &&return 1
done
return 0
}
if pingtest $HOSTS
#100% failed
echo "server failed at $(date)" | mail -s "server is down" mymail..
echo "host ($HOSTS) is down (ping failed) at $(date)"
else
echo "everyting is fine"
fi
but its sending me a mail even when there is connection to the server, and i only want it when the ping fails..
i have made the script run every 5 min. with crontab -e
5 * * * * filelocation
can someone please help me with this?
sorry if this is the wrong place to ask..