
Bash qui permet de vérifier, si les sites web sont down.
Marche uniquement avec linux, et Cygwin.
Créé 3 fichiers :
- emails.lst, qui contient la liste des emails.
- websites.lst qui contient la liste des sites web.
- checker_website.sh qui contient le script de vérification des sites web.
emails.lst
xxxx@xxxx.com xxx@xxxx.fr
websites.lst
www.monsite.com www.monautresite.com
checker_website.sh
#!/bin/bash # Website status checker. by ET (etcs.me) WORKSPACE=/cygdrive/d/Users/Angel/Projets/Macros/git # list of websites. each website in new line. leave an empty line in the end. LISTFILE=$WORKSPACE/websites.lst # Send mail in case of failure to. leave an empty line in the end. EMAILLISTFILE=$WORKSPACE/emails.lst # Temporary dir TEMPDIR=cache # `Quiet` is true when in crontab; show output when it's run manually from shell. # Set THIS_IS_CRON=1 in the beginning of your crontab -e. # else you will get the output to your email every time if [ -n "$THIS_IS_CRON" ]; then QUIET=true; else QUIET=false; fi function test { response=$(curl --write-out %{http_code} --silent --output /dev/null $1) filename=$( echo $1 | cut -f1 -d"/" ) if [ "$QUIET" = false ] ; then echo -n "$p "; fi if [ $response -eq 200 ] ; then # website working if [ "$QUIET" = false ] ; then echo -n "$response "; echo -e "\e[32m[ok]\e[0m" fi # remove .temp file if exist if [ -f $TEMPDIR/$filename ]; then rm -f $TEMPDIR/$filename; fi else # website down response=$(curl --write-out %{http_code} --silent --output /dev/null $1) if [ $response -eq 200 ] ; then # website working if [ "$QUIET" = false ] ; then echo -n "$response "; echo -e "\e[32m[ok]\e[0m" fi # remove .temp file if exist if [ -f $TEMPDIR/$filename ]; then rm -f $TEMPDIR/$filename; fi else if [ "$QUIET" = false ] ; then echo -n "$response "; echo -e "\e[31m[DOWN]\e[0m"; fi if [ ! -f $TEMPDIR/$filename ]; then while read e; do # using mailx command echo "WEBSITE DOWN ($response) $p" | email -s "WEBSITE DOWN ($response) $1" $e # using mail command #mail -s "$p WEBSITE DOWN" "$EMAIL" done < $EMAILLISTFILE #echo > $TEMPDIR/$filename fi fi fi } # main loop while read p; do test $p done < $LISTFILE