Skip to content

Instantly share code, notes, and snippets.

@jhalitschke
Created April 26, 2020 16:34
Show Gist options
  • Save jhalitschke/8bd05e095e35d05f67bfa2e86e256e4a to your computer and use it in GitHub Desktop.
Save jhalitschke/8bd05e095e35d05f67bfa2e86e256e4a to your computer and use it in GitHub Desktop.
check internet connectivity
#!/bin/bash
# check internet connectivity
# i use it to check and log every the connection
# just add a cron job with crontab -e
# * * * * * ~/check_connectivity.sh >> ~/check_connectivity.log
DATE=`date '+%Y-%m-%d %H:%M:%S'`
if ping -q -c 1 -W 1 8.8.8.8 >/dev/null; then
echo "$DATE - IPv4 is up"
else
echo "$DATE - IPv4 is down"
fi
if nc -zw1 google.com 443; then
echo "$DATE - We have connectivity to google.com."
else
echo "$DATE - No connection to google.com possible."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment