This commit is contained in:
kyodev 2018-01-19 16:47:16 +01:00
parent 75cb0307eb
commit 5e26b235ae
1 changed files with 19 additions and 16 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash
version=5/12/2017
version=16/01/2018
# si $1=all affichage complet
f__affichage(){ # 5/12/2017
@ -52,14 +52,18 @@ EOF
exit
}
# test wget, $1=url à tester, sortie du script (même si url testée ok) avec affichage erreur ou ok
f__error(){ # 16/01/2018 divert
:
}
# test wget, $1=url à tester, $2=''|print|loc|test
# par défaut, sortie du script (même si url testée ok) avec affichage erreur ou ok
# si $2=print affiche url testée & entêtes http & location, return 0
# si $2=loc affiche seulement location, return 0
# si $2=test return 0 si ok, return 1 si KO
f__wget_test(){ # 11/12/2017
local file_test_wget retourWget retourHttp location
f__wget_test(){ # 16/01/2018
local file_test_wget="/tmp/testWget-$script" retourWget retourHttp location
file_test_wget="/tmp/testWget-$$-$RANDOM"
wget -Sq --timeout=5 --tries=2 --user-agent="$user_agent" --spider --save-headers "$1" &>"$file_test_wget"
retourWget="$?"
[ "$retourWget" == 1 ] && retourWget="1: code erreur générique"
@ -73,36 +77,35 @@ f__wget_test(){ # 11/12/2017
retourHttp=$( grep -i 'HTTP/' "$file_test_wget" | tr -d '\n' | xargs )
location=$( grep -i 'location' $file_test_wget | xargs )
if [ "$2" == "test" ]; then
rm "$file_test_wget" 2>/dev/null
rm -f "$file_test_wget"
# spécial maintenance frama.link, pas de redirection sur page status framalink
[ "$( grep -c '303' <<< $retourHttp )" -ne 0 ] && return 1 # 303 See Other
grep -q '303' <<< $retourHttp && return 1 # 303 See Other
[ "$retourWget" == "0" ] && return 0 || return 1
fi
if [ "$2" == "print" ]; then
if [ "$retourWget" != "0" ]; then
echo "erreur wget: $RED$retourWget"
echo -e "$BLUE $1$STD\t$RED $retourHttp"
echo " erreur wget: erreur $RED$retourWget"
echo -e "$BLUE $1$STD\t$RED $retourHttp$STD"
else
echo -e "$BLUE $1$STD\t$GREEN $retourHttp"
echo -e "$BLUE $1$STD\t$GREEN $retourHttp$STD"
fi
echo "$STD"
fi
if [ "$2" == "print" ] || [ "$2" == "loc" ]; then
[ "$location" ] && echo -n "$YELLOW $location" || echo -n "$YELLOW no location"
echo "$STD"
rm "$file_test_wget" 2>/dev/null
rm -f "$file_test_wget"
return 0
fi
if [ "$retourWget" != "0" ]; then
rm "$file_test_wget" 2>/dev/null
# f__error "wget, $retourWget" "$1" "$YELLOW$retourHttp" "$location"
rm -f "$file_test_wget"
f__error "wget, erreur $retourWget" "$1" "$YELLOW$retourHttp" "$location"
echo -e "$RED erreur wget, $retourWget \n $1 \n $YELLOW$retourHttp \n $location$STD" # pour les diags
return 1
fi
if [ "$(grep -c '200' <<< $retourHttp)" -ne 0 ]; then
if grep -q '200' <<< $retourHttp; then
echo -e "$GREEN\ntout est ok, réessayer$STD\n"
fi
rm "$file_test_wget" 2>/dev/null
rm -f "$file_test_wget"
exit 0
}