#!/bin/bash
echo "$(date): Connect to Internet..."
pon rnet
sleep 5

x=0
# Wait until connection is established
while ! ping -c 1 8.8.8.8 &>/dev/null ; do
  echo "$(date): wait for internet connection to come up" 
  sleep 5 
  if [ $x -gt 10 ]; then
    # Time out here
    echo "$(date): Could not connect to internet (timeout)..."
    exit 1
  fi
  x=$((x+1))
done
echo "$(date): Connected to Internet..."
