• [^] # Re: cron+wget

    Posté par . En réponse au message recevoir automatiquement quotidiennement une page web ou screenshot de la page par mail. Évalué à 4.

    Bon, j'ai été un peu trop rapide.

    Moi, je ferai un script déclenché par un (ana)cron de manière périodique.

    Donc, wget ou curl pour récupérer la page intéressante, que l'on enregistre dans un fichier, disons, $PAGE.current. Si $PAGE.reference existe, on fait un diff $PAGE.current $PAGE.reference. S'il y a une différence, on envoie une mail via mailx et on écrase $PAGE.reference avec $PAGE.current.

    Ce qui, en script, donnerai à peu près ça:

    MON_SITE=1ドル
    DESTINATION=2ドル
    TARGET_MAIL=3ドル
    if test -z "$MON_SITE" || test -z "$DESTINATION" || test -z "$TARGET_MAIL"
    then
     printf "Usage: 0ドル URI DESTINATION TARGET\n\n\tURI: address of the page to spy\n\tDESTINATION: folder containing last image\n\tTARGET: mail address to which the mail will be sent\n\n"
     exit 1
    fi
    if test -d $DESTINATION
    then
     CUR_FILE="$DESTINATION/"$MON_SITE".current"
     REF_FILE="$DESTINATION/"$MON_SITE".reference"
     curl $MON_SITE > $CUR_FILE
     if test -e $REF_FILE && diff $CUR_FILE $REF_FILE
     then
     mailx -s "WebSite change: $MON_SITE" < $CUR_FILE
     rm $REF_FILE
     mv $CUR_FILE $REF_FILE
     fi
    else
     printf "$DESTINATION is not folder"
     exit 1
    fi

    Bon, je n'ai pas testé, il y a sûrement des ajustements à faire (déjà, le fait est que je n'ai pas tout blindé), mais c'est surtout pour décrire l'idée.