Last active
April 5, 2018 09:27
-
-
Save mklooss/d1735e2c5f0960d5d9f0 to your computer and use it in GitHub Desktop.
simple script: check if website is online
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 characters
| #!/bin/bash | |
| if [ -z "$1" ]; then | |
| echo "usage: onlinecheck [domain]" | |
| echo "example: onlinecheck www.heise.de" | |
| exit | |
| fi | |
| FOLDER="/tmp/onlinecheck/" | |
| MAILTO=root | |
| CHECK=`curl --http1.1 -s -I "$1" | grep HTTP | grep "200 OK"` | |
| MD5SUM=`echo -n "$1" | md5sum - | xargs | cut -f1 -d " "` | |
| FILENAME="${FOLDER}${MD5SUM}" | |
| if [ -z "$CHECK" ]; then | |
| mkdir -p $FOLDER | |
| echo "$1 is offline" | |
| if [ ! -f $FILENAME ]; then | |
| touch $FILENAME | |
| echo "send email" | |
| echo -n "$1 is offline" | mail -s "$1 is offline" $MAILTO | |
| fi | |
| else | |
| if [ -f $FILENAME ]; then | |
| echo -n "$1 is back online" | mail -s "$1 is back online" $MAILTO | |
| rm -f $FILENAME | |
| fi | |
| echo "$1 is online" | |
| fi | |
| if [ -d "$FOLDER" ]; then | |
| find $FOLDER -type f -mmin +60 -exec rm -f "{}" \; | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment