Skip to content

Instantly share code, notes, and snippets.

@kayo-tozaki
Created December 16, 2016 12:28
Show Gist options
  • Select an option

  • Save kayo-tozaki/2d81be1ae23bf564e5b13efd3e4bab03 to your computer and use it in GitHub Desktop.

Select an option

Save kayo-tozaki/2d81be1ae23bf564e5b13efd3e4bab03 to your computer and use it in GitHub Desktop.
get website status and send alert mail
LANG=ja_JP.utf8
CURL_DATA=`curl --connect-timeout 30 -vvvv http://<your.website.url> 2>&1 `
IF_DATA=`echo $CURL_DATA | grep "HTTP/1.1 200 OK"`
SENDER=`cat mail_flag`
DATE=`date +"%Y/%m/%d %H:%M:%S"`
if [ -n "$IF_DATA" ]; then
if [ "$SENDER" = "2" ]; then
echo -e "$DATE\n$CURL_DATA" | col -b | mailx -s 'Recovery' <send_alart@mail.address>
SENDER=1
fi
else
if [ "$SENDER" = "1" ]; then
echo -e "$DATE\n$CURL_DATA" | col -b | mailx -s 'Problem' <send_alart@mail.address>
SENDER=2
fi
fi
echo $SENDER > mail_flag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment