Last active
December 25, 2020 20:21
-
-
Save ulyssesr/556bc4c1ffb4238b6b666b7180f863c6 to your computer and use it in GitHub Desktop.
LightSail website monitoring script
This file contains 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 | |
#setting variables | |
now=$(date) | |
domain="https://$1" | |
log="webmon.log" | |
#checking if no arguments | |
if [[ $1 = "" ]]; then | |
echo "Format: webmon.sh https://domain.com" | |
exit | |
fi | |
#checking website | |
if curl -s --head --request GET $domain | grep "200 OK" > /dev/null; then | |
echo "$now $domain is UP." >> $log | |
else | |
echo "$now $domain is DOWN. Rebooting $domain." >> $log | |
aws lightsail reboot-instance --instance-name $1 --profile lightsail --region us-east-2 >> $log | |
fi | |
# add it to your crontab | |
# */5 * * * * /bin/bash /home/ubuntu/webmon.sh yourdomain.com | |
# cat the webmon.log to view the log. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment