#!/bin/bash

RES=`ping -W 2 -c 2 -q 8.8.8.8 2> /tmp/.ping_stat.txt | grep "0 received" | grep -v grep`
#FILESIZE=$(stat -c%s "")

# first method, success
if [ "$RES" = "" ] && [ ! -s "/tmp/.ping_stat.txt" ]; then
  echo "YES"
else
  # check second method (some networks have network but doesn't ping)
  wget --timeout=2 -q --spider http://google.com

  if [ $? -eq 0 ]; then
    echo "YES"
  else
    echo "NO"
  fi
fi

