Thursday, September 1, 2011

Bash script to check internet connection

#!/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



It tries to download google page within 5 seconds
returns 'yes' if google page index is downloaded
else return 'no'