Skip to content

Instantly share code, notes, and snippets.

@meg23
Created January 23, 2017 22:12
Show Gist options
  • Save meg23/a9981f22cafb783a5b07b2861440ae5f to your computer and use it in GitHub Desktop.
Save meg23/a9981f22cafb783a5b07b2861440ae5f to your computer and use it in GitHub Desktop.
#!/bin/bash
fetch ()
{
site=$1
echo Trying to fetch $site...
timeout 25 wget -O /dev/null -q $site
}
test_if_up ()
{
fetch www.google.com
if [[ $? == "0" ]]
then
echo Okay, so your internet is working...
SITE=$1
EMAIL=$2
if [[ ! -f ~/"$SITE"_delete_me ]]
then
fetch $SITE
if [[ $? -ne "0" ]]
then
echo Sleeping for 30 seconds and then trying again...
sleep 30
fetch $SITE
if [[ $? -ne "0" ]]
then
echo "Site is down!" | mailx -s "$SITE down!" $EMAIL
touch ~/"$SITE"_delete_me
fi
fi
else
fetch $SITE
if [[ $? = "0" ]]
then
echo "Site is backup again!" | mailx -s "$SITE back up!" $EMAIL
rm ~/"$SITE"_delete_me
fi
fi
fi
}
#-----------------------------------
# ADD WEBSITES BELOW
#-----------------------------------
test_if_up example.com [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment