Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: A Tiny Bash script to check Internet connection availability  (Read 1810 times)

0 Members and 1 Guest are viewing this topic.

vinayakk

  • Guest
A Tiny Bash script to check Internet connection availability
« on: January 03, 2014, 05:05:15 am »
Below is the tiny bash script to check Internet connection availability

#!/bin/bash

WGET="/usr/bin/wget"

$WGET -q --tries=10 --timeout=5 http://www.google.com -O /tmp/index.google &> /dev/null
if [ ! -s /tmp/index.google ];then
   echo "no"
else
   echo "yes"
fi



As you see it tries to download google’s index page, if it’s not empty script returns “yes”, if there is no Internet connection available script will return “no”. If it is impossible to fetch the page in more than 5 seconds script will return “no” as well.

 :)