Watch for a host to go down and then send an email notification
#!/bin/bash
function mailme {
msg=$1;
if [[ "${msg}" != "" ]]; then
# The following will send a text message to the phone number specified in the "to" on the AT&T network.
to="812555555@txt.att.net";
subject="Apache DOWN!!!";
body="${msg}";
echo $body | mail -s $subject $to;
fi
}
curl -fIsk http://www.url-to-check.com >> /dev/null;
if [[ $? > 0 ]]; then
mailme "Web server is down!!!";
fi
ping -qc1 www.host-to-ping.com > /dev/null 2>&1;
if [[ $? > 0 ]]; then
mailme "host-to-ping.com is down!!!";
fi
function mailme {
msg=$1;
if [[ "${msg}" != "" ]]; then
# The following will send a text message to the phone number specified in the "to" on the AT&T network.
to="812555555@txt.att.net";
subject="Apache DOWN!!!";
body="${msg}";
echo $body | mail -s $subject $to;
fi
}
curl -fIsk http://www.url-to-check.com >> /dev/null;
if [[ $? > 0 ]]; then
mailme "Web server is down!!!";
fi
ping -qc1 www.host-to-ping.com > /dev/null 2>&1;
if [[ $? > 0 ]]; then
mailme "host-to-ping.com is down!!!";
fi