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
3 comments:
good one .. thanks
ping -c 3 google.com
correct, or you can use this script:
http://linuxpoison.blogspot.com/2012/05/bash-script-check-servers-availability.html
Post a Comment