From 30b0bb0e79c4917364cf66b82ac8782fff9f8cbd Mon Sep 17 00:00:00 2001 From: tykayn Date: Thu, 26 Nov 2020 18:43:53 +0100 Subject: [PATCH] counter with numeric month --- rapport_activite/rapport_activite.sh | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/rapport_activite/rapport_activite.sh b/rapport_activite/rapport_activite.sh index 61ef172..fce39f4 100755 --- a/rapport_activite/rapport_activite.sh +++ b/rapport_activite/rapport_activite.sh @@ -103,12 +103,14 @@ generateSpecificReport() local numMonth="$4" local errorLogFormatDate="$2/$4" local accessLogFormatDate="$1/$2" +# echo " errorLogFormatDate $errorLogFormatDate" +# echo " accessLogFormatDate $accessLogFormatDate" # nginx shows logs like this: - # error log format: - # 2020/11/19 + # --------------------- error log format: + # --------------------- 2020/11/19 # 2020/11/19 20:31:05 [error] 1720#1720: *40 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.93, server: mobilizon.chapril.org, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:4000/", host: "mobilizon.chapril.org" - # access log, format : - # 26/Nov/2020 + # --------------------- access log, format : + # --------------------- 26/Nov/2020 # 192.168.1.93 - - [26/Nov/2020:18:06:05 +0100] "GET / HTTP/1.1" 200 2731 "-" "check_http/v2.2 (monitoring-plugins 2.2)" # 7d01:4f8:14b:c41::12 - - [26/Nov/2020:18:07:06 +0100] "POST /api/ HTTP/1.1" 200 238 "-" "curl/7.64.0" @@ -126,7 +128,6 @@ generateSpecificReport() echo "Nombre total d'ip utilisatrices du service = $((ipv4UserCount+ipv6UserCount))" echo "Nombre total d'erreurs = $errorsCount" -# echo "Nombre de comptes utilisateurs = " show "numberOfEvents" show "numberOfLocalEvents" show "numberOfGroups" @@ -145,7 +146,7 @@ generateSpecificReport() generateReport() { echo "Rapport d'activité du service $SERVICE_NAME de $monthEnglish $year" - echo + echo "" echo "=================================================================" echo generateHTTPReport "$1" "$2" "$3" "$4" @@ -160,6 +161,7 @@ if [ "$#" = 1 ] && [ "$1" = "-h" ]; then elif [ "$#" = 1 ] && [ "$1" = "-p" ]; then if [ "$(date +%m)" -gt 1 ]; then precedingMonth="$((10#$(date +%m)-1))" + year="$(date +%Y)" if [ $precedingMonth -lt 10 ]; then yearMonth="$year-0$precedingMonth" @@ -170,6 +172,7 @@ elif [ "$#" = 1 ] && [ "$1" = "-p" ]; then precedingMonth=12 year="$(($(date +%Y)-1))" yearMonth="$year-$precedingMonth" + fi monthEnglish=$(LANG=en_EN.UTF-8;date -d $year-$precedingMonth-01 +%b) generateReport "$monthEnglish" "$year" "$yearMonth" "$precedingMonth" @@ -183,10 +186,10 @@ elif [ "$#" -eq 2 ]; then elif ! (let "$2") 2>/dev/null; then echo -e "L'année doit être numérique." help - elif [ "$2" -lt 2018 ] || [ "$2" -gt "$(date +%Y)" ]; then - echo -e "Année non valable $2." + elif [ "$2" -lt 2020 ] || [ "$2" -gt "$(date +%Y)" ]; then + echo -e "Année non valable $2. Le service a été mis en ligne en Novembre 2020" help - elif [ "$2" -le 2017 ] || [ "$2" -ge $(($(date +%Y)+1)) ] ; then + elif [ "$2" -le 2020 ] || [ "$2" -ge $(($(date +%Y)+1)) ] ; then echo -e "Pas de données pour ce mois." help else @@ -197,13 +200,16 @@ elif [ "$#" -eq 2 ]; then fi monthEnglish=$(LANG=en_EN.UTF-8;date -d "$2-$1-01" +%b) year="$2" - generateReport "$monthEnglish" "$year" "$yearMonth" + echo "et HOP ===================" + generateReport "$monthEnglish" "$year" "$yearMonth" "$1" fi elif [ "$#" -eq 0 ]; then yearMonth="$(date +%Y-%m)" + monthNumeric=$(date +%m) monthEnglish=$(LANG=en_EN.UTF-8;date +%b) year="$(date +%Y)" - generateReport "$monthEnglish" "$year" "$yearMonth" + echo "et TADAM ===================" + generateReport "$monthEnglish" "$year" "$yearMonth" $(date +%m) else echo -e "Bad parameter." help