Below is simple bash script to test the Internet connection using wget utility.
Feel free to copy and use this script
Feel free to copy and use this script
Source: cat internet_connection.sh
#!/bin/bash
HOST=$1
WGET="/usr/bin/wget"
$WGET -q --tries=10 --timeout=5 $HOST
RESULT=$?
if [[ $RESULT -eq 0 ]]; then
echo "Connection made successfully to $HOST"
else
echo "Fail to make connection to $HOST"
fi
Output:
./internet_connection.sh http://yahoo.com
Connection made successfully to http://yahoo.com
./internet_connection.sh http://yahosssss.com
Fail to make connection to http://yahosssss.com
#!/bin/bash
HOST=$1
WGET="/usr/bin/wget"
$WGET -q --tries=10 --timeout=5 $HOST
RESULT=$?
if [[ $RESULT -eq 0 ]]; then
echo "Connection made successfully to $HOST"
else
echo "Fail to make connection to $HOST"
fi
Output:
./internet_connection.sh http://yahoo.com
Connection made successfully to http://yahoo.com
./internet_connection.sh http://yahosssss.com
Fail to make connection to http://yahosssss.com
source:http://linuxpoison.blogspot.com/2012/09/135781677519016.html