Last active
June 11, 2020 14:07
-
-
Save jakekara/830201b418fb1d8bc33afbc4333b1995 to your computer and use it in GitHub Desktop.
bash script to check ever minute if a given site is online
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
#!/usr/bin/env sh | |
# | |
# netyet.sh - check a site every minute until it's back online | |
# jake@jakekara.com | |
# | |
# usage: netyet.sh google.com | |
# | |
# Read the site as the only command line arg | |
SITE=$1 | |
# Sleep for 60 seconds between retries (eventually make this an arg) | |
SECONDS=60 | |
while [ 1 ] | |
do | |
# test the site. ping sets exit status to 0 if successful | |
ping -c1 $SITE > /dev/null 2>&1 | |
if [ $? = 0 ]; then | |
# success | |
echo "$(date): $SITE online." | |
say "$SITE is online" | |
break | |
else | |
# failure | |
echo "$(date): Failed to load $SITE" | |
sleep $SECONDS | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment