Last active
August 9, 2018 15:01
-
-
Save johnmurch/11b887d340defc40d0b1f3509621d7a0 to your computer and use it in GitHub Desktop.
Ghetto Pi Monitor & Server Restart
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 | |
LOGFILE="/home/pi/status.log" | |
MAILGUN_API_KEY="XXXXXXXX" | |
MAILGUN_DOMAIN="XXXXXX" | |
SENDER="XXXXXXX" | |
RECEPIENT="XXXXX" | |
SUBJECT="Server Down" | |
TEXT="Restarting Server..." | |
echolog() | |
( | |
echo $1 | |
echo $1 >> $LOGFILE | |
) | |
while [ : ] | |
do | |
api=`curl -s "https://api.domain.com" | grep -c "API"` | |
webpage=`curl -s "https://www.domain.com" | grep -c "Hello"` | |
tracking=`curl -s "https://tracking.domain.com" | grep -c "Tracking"` | |
portal=`curl -s "https://portal.domain.com" | grep -c "Portal"` | |
if [ "$api" != "0" ] && [ "$webpage" != "0" ] && [ "$tracking" != "0" ] && [ "$portal" != "0" ]; then | |
echolog "`date +"%Y-%m-%d %T"` UP" | |
sleep 120 | |
else | |
echolog "`date +"%Y-%m-%d %T"` DOWN" | |
curl -s --user "api:$MAILGUN_API_KEY" \ | |
https://api.mailgun.net/v3/"$MAILGUN_DOMAIN"/messages \ | |
-F from="$SENDER" \ | |
-F to="$RECEPIENT" \ | |
-F subject="$SUBJECT" \ | |
-F text="$TEXT" | |
curl -X POST "https://webhook.domain.com/restart-server" | |
sleep 300 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Super ghetto but wanted a simple remote bot to monitor a website and restart it if it's down. Also sends an email to let me know.