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

Page Comments (Click to edit)

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Powered by pmwiki-2.2.0-beta65