Created
July 10, 2022 04:52
-
-
Save skys215/945b902bd4d4c37544517e491eaaf50b to your computer and use it in GitHub Desktop.
Check connectivity and show notification(MacOS)
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 | |
# Define domains to be checked | |
Domains=(http://example1.com https://example2.com) | |
# Title of Notification | |
TITLE="Site connectivity check" | |
# Sound are in /System/Library/Sounds | |
SOUND="Glass" | |
for N in "${Domains[@]}" ; do | |
Domain=$N | |
# Get HTTP status code using CURL | |
Status_Code=$(curl --connect-timeout 3 -s -X GET -0 -H 'User-Agent:' -w %{http_code} -o /dev/null ${Domain}) | |
msg='' | |
# Check if status code is between 200-300 | |
if [ "$Status_Code" -ge 200 ];then | |
if [ "$Status_Code" -lt 300 ];then | |
msg='' | |
else | |
msg="❌ ${Domain} returned ${Status_Code}" | |
osascript -e 'display notification "'"$msg"'" with title "'"$TITLE"'" sound name "'"$SOUND"'"' | |
fi | |
fi | |
done |
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
# Run script every 2 hours between 0-10 o'clock, every hour between 11-23 o'clock | |
0 0-10/2,11-23 * * * /bin/bash /path/to/connectivity_check.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment