Skip to content

Instantly share code, notes, and snippets.

@madprops
Last active March 3, 2024 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madprops/2c74123bd3d8305c03697d1df6007193 to your computer and use it in GitHub Desktop.
Save madprops/2c74123bd3d8305c03697d1df6007193 to your computer and use it in GitHub Desktop.
Bash script to check for network status
#!/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