Created
October 3, 2014 12:57
-
-
Save nyxz/a7a4d17e0acf6bced660 to your computer and use it in GitHub Desktop.
Revisions
-
nyxz created this gist
Oct 3, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ #!/bin/bash #========================================================== # This script checks if your servers are up and running. If # server is down it sends an email to the email(s) listed in # $EMAIL. # The script requires you to have `mailx` setup. #========================================================== # Set connect timeout to 1min TIMEOUT=60 # Receiver Email. Can be a comma separated list of emails. EMAIL='[email protected]' function getStatusCode { local result=$1 local host=$2 local cmd="curl --connect-timeout $TIMEOUT -s -o /dev/null -w \"%{http_code}\" $host" eval $result=$($cmd) } function checkCode { local code=$1 local host=$2 if [ $code != '200' -a $code != '302' ] then sendEmail "Server at $host is down." else echo "Server at $host is up." fi } function sendEmail { local msg=$1 echo $msg | mailx -A gmail -s "Server Report" $EMAIL } function isUp { local host=$1 getStatusCode code $host checkCode $code $host } #========================================================== # Define your servers here: #========================================================== SERVERS=(\ 'http://server1.com' \ 'http://server2.com' \ ) for server in ${SERVERS[@]} do isUp $server done