LOGIN=internet        # usuario
DOMAIN=speedy.com.br  # provedor
PASSWORD=internet     # senha
URL=www.google.com    # url sem javascript

speedy_login() {
  elinks -dump "http://200.171.222.97/wsc/servlet/logon.do?opcion=internet&CPURL=&username=${LOGIN}@${DOMAIN}&password=${PASSWORD}" | grep -iEq "speedy"
  if [ "$?" = "0" ] ; then
    echo "Erro de autenticacao no Speedy. Verifique o login e a senha."
    exit 1
  fi
  echo "Autenticacao no Speedy realizada com sucesso em $(date +"%d/%m/%Y %H:%M")."
}

ping -c 2 ${URL} > /dev/null
if [ "$?" != "0" ] ; then
  elinks -dump "${URL}" | grep -iEq "speedy"
  if [ "$?" = "0" ] ; then
    speedy_login
  fi
fi

