linux poison RSS
linux poison Email

Bash Script: Script to check internet connection

Below is simple bash script to test the Internet connection using wget utility.
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




3 comments:

Amit Chudasama said...

good one .. thanks

diego said...

ping -c 3 google.com

DevOps said...

correct, or you can use this script:

http://linuxpoison.blogspot.com/2012/05/bash-script-check-servers-availability.html

Post a Comment

Related Posts with Thumbnails