Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script to check if Internet is reachable (infinity loop)
#!/bin/bash
echo "Started at $(date)"
while true
do
nc -z 8.8.8.8 53 >/dev/null 2>&1
online=$?
if [ $online -eq 0 ]; then
echo "Online"
else
echo "Offline at $(date)"
fi
sleep 20
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.