Last active
March 3, 2024 21:36
-
-
Save madprops/2c74123bd3d8305c03697d1df6007193 to your computer and use it in GitHub Desktop.
Bash script to check for network status
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 bash | |
status="down" | |
while true; do | |
ping -w 10 -c 1 8.8.8.8 > /dev/null 2>&1 | |
ping_status=$? | |
if [ $ping_status -eq 0 ] && [ "$status" == "down" ]; then | |
timestamp=$(date +"%H:%M:%S") | |
echo "Network is Up - ${timestamp}" | |
notify-send "Network is Up" | |
status="up" | |
elif [ $ping_status -ne 0 ] && [ "$status" == "up" ]; then | |
timestamp=$(date +"%H:%M:%S") | |
echo "Network is Down - ${timestamp}" | |
notify-send "Network is Down" | |
status="down" | |
fi | |
sleep 10 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment