sexta-feira, 17 de outubro de 2008

Será que atualizou?

Está esperando resultado do vestibular? Acompanhando a emcomenda no site dos correios? Você não desgruda da tecla F5? Seus problemas ACABARAM!!!

Este script deixa você calmo e tranqüilo fazendo seu trabalho que ele fica 1 vez por minuto verificando se o site foi atualizado para você!

Uma Dica! Se você usa Gnome, troque os "kdialog" por "gdialog" ;)


#!/bin/bash
# Verify if website was Updated
#
# Copyright (C) 2008 Thomaz de Oliveira dos Reis
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

#Tempo de espera para cada download.
TEMPO=1m
#Taxa de erro para desistir...
TAXA_ERRO=3

ORIGINAL="/tmp/file.original.$$"
NOVO="/tmp/file.novo.$$"
ERRO=0
if ! wget "$1" -O $ORIGINAL
then
kdialog --msgbox "Não consegui baixar a página! tente novamente!"
rm $ORIGINAL $NOVO
exit 1
fi
cp $ORIGINAL $NOVO

while diff $ORIGINAL $NOVO
do
sleep $TEMPO
mv $NOVO $ORIGINAL
if ! wget "$1" -O $NOVO
then
ERRO=$(( $ERRO + 1 ))
if [ "$ERRO" == "$TAXA_ERRO" ]
then
kdialog --msgbox "O site \"$1\" está inacessível. O script parou."
rm $ORIGINAL $NOVO
exit 1
fi
cp $ORIGINAL $NOVO
fi
done

kdialog --msgbox "\"$1\" Foi atualizado!"