Saturday, June 30, 2018

Bash Script Script to check internet connection

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




visit link download

No comments:

Post a Comment