From 9d053e3eb41671838006063fbf00c89bcdb52fea Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 22 Jan 2023 21:07:54 +0100 Subject: [PATCH] getinfo error 400/404 --- roles/deploy-web/files/getinfo_day.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/roles/deploy-web/files/getinfo_day.sh b/roles/deploy-web/files/getinfo_day.sh index 8359861..7138390 100755 --- a/roles/deploy-web/files/getinfo_day.sh +++ b/roles/deploy-web/files/getinfo_day.sh @@ -1,5 +1,6 @@ #!/bin/bash DIRECTORY=/home/valentin/mail +SERVER_LOG=/var/log/nginx TOKEN=af920d2f7dbe97 DATE=$(date +%Y%m%d-%H%M%S) HOST=($(cat /etc/sentinel/virtualhost)) @@ -15,9 +16,11 @@ fi for i in ${HOST[@]} do directory_host=$DIRECTORY/$i/$WEEK - log_access=/var/log/nginx/${i}_access.log.1 + log_access=${SERVER_LOG}/${i}_access.log.1 mkdir -pv $directory_host cat $log_access | grep "|" | awk -F "|" '{print $1}' | sort | uniq > $directory_host/list_$DATE + cat $log_access | awk -F "|" '{ if($2 == "404") print $1}' > $directory_host/404_$DATE + cat $log_access | awk -F "|" '{ if($2 == "400") print $1}' > $directory_host/400_$DATE while read line; do if grep $line $DIRECTORY/*/*/output_*.txt > /dev/null 2>&1; then grep -h -B1 -A8 $line $DIRECTORY/*/*/output_*.txt |head -10 >> $directory_host/output_$DATE.txt @@ -25,7 +28,7 @@ do curl "ipinfo.io/$line?token=$TOKEN" >> $directory_host/output_$DATE.txt fi echo >> $directory_host/output_$DATE.txt -done <$directory_host/list_$DATE + done <$directory_host/list_$DATE echo "nombre de visite : $(wc -l $directory_host/list_$DATE |cut -d ' ' -f1)" > /tmp/mail echo "nombre de visite par pays, par region et par ville : " >> /tmp/mail LIST=("country" "region" "city") @@ -35,11 +38,13 @@ done <$directory_host/list_$DATE cat $directory_host/output_$DATE.txt |grep "${j}" |sort |uniq -c >> /tmp/mail echo "--------------" >> /tmp/mail done - echo "nombre erreur 400 par IP : " >> /tmp/mail - cat $log_access | awk -F "|" '{ if($2 == "400") print $1}' |sort |uniq -c >> /tmp/mail - echo "--------" >> /tmp/mail - echo "nombre erreur 404 par IP : " >> /tmp/mail - cat $log_access | awk -F "|" '{ if($2 == "404") print $1}' |sort |uniq -c >> /tmp/mail + ERROR=("400" "404") + for j in ${ERROR[@]} + do + echo "nombre erreur ${j} par IP : " >> /tmp/mail + cat $directory_host/${j}_$DATE |sort |uniq -c >> /tmp/mail + echo "--------" >> /tmp/mail + done cat /tmp/mail |mail -s "Rapport reverse proxy $DATE" -A $directory_host/output_$DATE.txt valczebackup@gmail.com #rm $directory_host/* done