Multi check en cas d'erreur avec envoi de mail au bout d'un trop grand nombre d'erreur + Ajout de l'URL de download dans le mail

This commit is contained in:
root 2010-10-07 11:03:56 +02:00
parent 1cec8ada0c
commit ca37c41cd3

View file

@ -1,18 +1,64 @@
#!/bin/bash
RC_HOME=/var/www/webmail/public_html
MAIL=root
TIME=7
SEND_EVERY_NB_DAY=7
CACHE=/var/www/webmail/.cache_check_upgrade
CACHE_FAILED=$CACHE.failed
MAX_CHECK=10
MAX_FAILED=3
SLEEP_ON_FAILED=10
CHECK_URL=http://www.roundcube.net/download
DEBUG=0
[ "$1" == "-v" ] && DEBUG=1
current=`egrep "define.*RCMAIL_VERSION" /var/www/webmail/public_html/program/include/iniset.php|sed "s/define('.*', '\([^']*\)'.*$/\1/"`
current=`egrep "define.*RCMAIL_VERSION" $RC_HOME/program/include/iniset.php|sed "s/define('.*', '\([^']*\)'.*$/\1/"`
[ $DEBUG -eq 1 ] && echo "Current : $current"
newest=`wget -q http://www.roundcube.net/download -O - |grep Stable|sed 's/^.*Stable.*: \(.*\)<\/td>.*$/\1/'`
for i in `seq 1 $MAX_CHECK`
do
tmpfile=`mktemp`
wget -q $CHECK_URL -O $tmpfile
newest=`cat $tmpfile|grep Stable|sed 's/^.*Stable.*: \(.*\)<\/td>.*$/\1/'`
if [ -n "$newest" ]
then
[ $DEBUG -eq 1 ] && echo "Newest : $newest"
rm -f $CACHE_FAILED > /dev/null 2>&1
DOWNLOAD_URL=`cat $tmpfile|grep "$newest"|grep "tar.gz"|head -1|sed 's/.* href="\([^"]*\)" .*$/\1/'`
[ $DEBUG -eq 1 ] && echo "Download URL : $DOWNLOAD_URL"
[ ! -n "$DOWNLOAD_URL" ] && DOWNLOAD_URL="$CHECK_URL" && [ $DEBUG -eq 1 ] && echo "Use check URL as download URL : $DOWNLOAD_URL"
rm -f $tmpfile > /dev/null 2>&1
break;
elif [ $i -eq $MAX_CHECK ]
then
error="Site du projet injoignable (ou structure du site modifie !!) => Impossible de recuperer le numero de la version stable actuel."
[ $DEBUG -eq 1 ] && echo $error
if [ -f $CACHE_FAILED ]
then
NB=`cat $CACHE_FAILED`
[ $DEBUG -eq 1 ] && echo "Fichier de cache d'erreur existe : $NB echec. Max : $MAX_FAILED"
if [ $NB -lt $MAX_FAILED ]
then
let NNB=NB+1
[ $DEBUG -eq 1 ] && echo "Augmentation du nb d'erreur dans le fichier de cache d'erreur : $NB -> $NNB"
echo -n $NNB > $CACHE_FAILED
else
[ $DEBUG -eq 1 ] && echo "MAX_FAILED atteint : on envoi un mail"
echo $error|mail -s "New RoundCude release check : FAILED" $MAIL
fi
else
[ $DEBUG -eq 1 ] && echo "Fichier de cache d'erreur n'existe pas : on l'initialise à 1."
echo -n 1 > $CACHE_FAILED
fi
[ $DEBUG -eq 1 ] && echo "exit 1"
exit 1
fi
[ $DEBUG -eq 1 ] && echo "Check failed ($i/$MAX_CHECK) : Sleep $SLEEP_ON_FAILED second before try again ..."
sleep $SLEEP_ON_FAILED
done
if [ "$newest" != "$current" ]
then
@ -21,11 +67,13 @@ then
echo "=====================" >> $tmp
echo "Current : $current" >> $tmp
echo "Newest : $newest" >> $tmp
echo >> $tmp
echo "Download URL : $DOWNLOAD_URL" >> $tmp
M=0
if [ -f $CACHE ]
then
if [ "`diff $tmp $CACHE`" != "" -o `find $CACHE -mtime +$TIME | wc -l` -eq 1 ]
if [ "`diff $tmp $CACHE`" != "" -o `find $CACHE -mtime +$SEND_EVERY_NB_DAY | wc -l` -eq 1 ]
then
[ $DEBUG -eq 1 ] && echo "Cache trop vieux ou modif => On envoi"
M=1