Skip to content

Instantly share code, notes, and snippets.

@ImBIOS
Created October 30, 2024 02:04
Show Gist options
  • Save ImBIOS/cfe5e334803eaeede1619f0c1f16fe30 to your computer and use it in GitHub Desktop.
Save ImBIOS/cfe5e334803eaeede1619f0c1f16fe30 to your computer and use it in GitHub Desktop.
This Bash script is designed to help you automatically execute commands once an internet connection is detected. Ideal for developers, sysadmins, and power users, this script repeatedly pings a specified server (default: Google) until a successful response is received, then runs any command you specify. Use it to automate tasks that depend on in…
#!/bin/bash
# Check if a command is passed
if [ -z "$1" ]; then
echo "Started internet watchdog!"
else
echo "Usage: $0; <command>"
exit 1
fi
# Loop until internet is available
until ping -c 1 google.com >/dev/null 2>&1; do
echo "Waiting for internet connection..."
sleep 5
done
echo "Internet is available. Executing the next command..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment