Skip to content

Instantly share code, notes, and snippets.

@ulyssesr
Last active December 25, 2020 20:21
Show Gist options
  • Save ulyssesr/556bc4c1ffb4238b6b666b7180f863c6 to your computer and use it in GitHub Desktop.
Save ulyssesr/556bc4c1ffb4238b6b666b7180f863c6 to your computer and use it in GitHub Desktop.
LightSail website monitoring script
#!/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