From 302d2303c730a8e4662177588be49a045b6fb041 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Mon, 17 Jun 2024 02:18:17 +0200 Subject: [PATCH] Declare and assign separately to avoid masking return values --- rapport_activite/rapport_activite.sh | 55 ++++++++++++++++++---------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/rapport_activite/rapport_activite.sh b/rapport_activite/rapport_activite.sh index ad50462..c1fd208 100755 --- a/rapport_activite/rapport_activite.sh +++ b/rapport_activite/rapport_activite.sh @@ -50,22 +50,28 @@ generateHTTPReport() echo "=§= Rapport d'activité HTTP" echo - local httpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep -c $year) + local httpRequestCount + httpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep -c "$year") echo "Nombre total de requêtes http = $httpRequestCount" - local trueHttpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep $year|grep -vi bot|grep -c -v check_http) + local trueHttpRequestCount + trueHttpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -c -v check_http) echo "Nombre de vraies requêtes http = $trueHttpRequestCount" - local botRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -i bot|grep -c -v check_http) + local botRequestCount + botRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -i bot|grep -c -v check_http) echo "Nombre de requêtes bot = $botRequestCount" - local errorRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-error.log*|grep -c "$year") + local errorRequestCount + errorRequestCount=$(zgrep "$monthEnglish" "$LOG_PREFIX-error.log*"|grep -c "$year") echo "Nombre de requêtes http en erreur = $errorRequestCount" - local ipv4VisitorCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep -E "^$IPV4_PATTERN "|cut -d' ' -f1|sort|uniq|wc -l ) + local ipv4VisitorCount + ipv4VisitorCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep -E "^$IPV4_PATTERN "|cut -d' ' -f1|sort|uniq|wc -l ) echo "Nombre d'ipv4 ayant visité le service = $ipv4VisitorCount" - local ipv6VisitorCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep -E "^$IPV6_PATTERN "|cut -d' ' -f1|sort|uniq|wc -l ) + local ipv6VisitorCount + ipv6VisitorCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep -E "^$IPV6_PATTERN "|cut -d' ' -f1|sort|uniq|wc -l ) echo "Nombre d'ipv6 ayant visité le service = $ipv6VisitorCount" echo "Nombre total d'ip ayant visité le service = $((ipv4VisitorCount+ipv6VisitorCount))" @@ -95,45 +101,56 @@ generateSpecificReport() # https://forge.chapril.org/api/swagger #$(curl -s --dump-header - "https://forge.chapril.org/api/v1/admin/orgs?limit=1&page1&token=$GITEA_API_KEY" > t) #$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=1&token=$GITEA_API_KEY" | jq '. | length' > t) - local accountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data | length') + local accountCount + accountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data | length') echo "Nombre de comptes = $accountCount" - local connectedAccountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data[].last_login' | grep -cv "1970") + local connectedAccountCount + connectedAccountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data[].last_login' | grep -cv "1970") echo "Nombre de comptes connectés au moins une fois = $connectedAccountCount" - local unconnectedAccountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data[].last_login' | grep -c "1970") + local unconnectedAccountCount + unconnectedAccountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data[].last_login' | grep -c "1970") echo "Nombre de comptes jamais connectés = $unconnectedAccountCount" #$(curl -s "https://forge.chapril.org/api/v1/admin/orgs?limit=100000&token=$GITEA_API_KEY" | jq '. | length' > t) - local organizationCount=$(curl -s "https://forge.chapril.org/api/v1/admin/orgs?limit=100000&token=$GITEA_API_KEY" | jq '. | length') + local organizationCount + organizationCount=$(curl -s "https://forge.chapril.org/api/v1/admin/orgs?limit=100000&token=$GITEA_API_KEY" | jq '. | length') if [[ -z "$organizationCount" ]]; then organizationCount=0 fi echo "Nombre d'organisations = $organizationCount" #$(curl -s "https://forge.chapril.org/api/v1/orgs?limit=100000" > t) - local publicOrganizationCount=$(curl -s "https://forge.chapril.org/api/v1/orgs?limit=100000" | jq '. | length') + local publicOrganizationCount + publicOrganizationCount=$(curl -s "https://forge.chapril.org/api/v1/orgs?limit=100000" | jq '. | length') if [[ -z "$publicOrganizationCount" ]]; then publicOrganizationCount=0 fi echo "Nombre d'organisations publiques = $publicOrganizationCount" - local repositoryCount=$(curl -s --dump-header - "https://forge.chapril.org/api/v1/repos/search?limit=1&token=$GITEA_API_KEY" | grep "X-Total-Count\:" | awk '{ print $2 }' | jq '.') + local repositoryCount + repositoryCount=$(curl -s --dump-header - "https://forge.chapril.org/api/v1/repos/search?limit=1&token=$GITEA_API_KEY" | grep "X-Total-Count\:" | awk '{ print $2 }' | jq '.') echo "Nombre de dépôts = $repositoryCount" - local publicRepositoryCount=$(curl -s --dump-header - "https://forge.chapril.org/api/v1/repos/search?limit=1" | grep "X-Total-Count\:" | awk '{ print $2 }' | jq '.') + local publicRepositoryCount + publicRepositoryCount=$(curl -s --dump-header - "https://forge.chapril.org/api/v1/repos/search?limit=1" | grep "X-Total-Count\:" | awk '{ print $2 }' | jq '.') echo "Nombre de dépôts publics = $publicRepositoryCount" - local repositorySpaceDisk=$(du -sh "$GITEA_REPO_HOME" | head -1 | awk '{ print $1 } ') + local repositorySpaceDisk + repositorySpaceDisk=$(du -sh "$GITEA_REPO_HOME" | head -1 | awk '{ print $1 } ') echo "Espace disque occupé par les dépôts = $repositorySpaceDisk" - local directoryCount=$(find "$GITEA_REPO_HOME" -type d | wc -l ) + local directoryCount + directoryCount=$(find "$GITEA_REPO_HOME" -type d | wc -l ) echo "Nombre de dossiers de l'espace disque = $directoryCount" - local fileCount=$(find "$GITEA_REPO_HOME" -type f | wc -l ) + local fileCount + fileCount=$(find "$GITEA_REPO_HOME" -type f | wc -l ) echo "Nombre de fichiers de l'espace disque = $fileCount" - local totalFileCount=$(find "$GITEA_REPO_HOME" | wc -l ) + local totalFileCount + totalFileCount=$(find "$GITEA_REPO_HOME" | wc -l ) echo "Nombre total de fichiers de l'espace disque = $totalFileCount" echo @@ -169,13 +186,13 @@ elif [ "$#" = 1 ] && [ "$1" = "-p" ]; then year="$(($(date +%Y)-1))" yearMonth="$year-$precedingMonth" fi - monthEnglish=$(LANG=en_EN.UTF-8;date -d $year-$precedingMonth-01 +%b) + monthEnglish=$(LANG=en_EN.UTF-8;date -d "$year-$precedingMonth-01" +%b) generateReport "$monthEnglish" "$year" "$yearMonth" elif [ "$#" -eq 2 ]; then if ! (let "$1") 2>/dev/null; then echo -e "Le mois doit être numérique." help - elif ([ "$1" -lt 1 ] || [ "$1" -gt 12 ]); then + elif [ "$1" -lt 1 ] || [ "$1" -gt 12 ]; then echo -e "Numéro du mois non valable $1." help elif ! (let "$2") 2>/dev/null; then