#!/bin/bash MAIL=/tmp/mail DIRECTORY=/home/valentin/mail SERVER_LOG=/var/log/nginx TOKEN=$(cat /etc/sentinel/token) DATE=$(date +%Y%m%d-%H%M%S) HOST=($(cat /etc/sentinel/virtualhost)) WEEK=$(date +%V) DAY=$(date +%u) if [ ${DAY} -eq 1 ]; then if [ ${WEEK} -ne "01" ]; then WEEK=$(echo "$WEEK-1" |bc) if [ ${#WEEK} -eq 1 ]; then WEEK="0${WEEK}" fi else WEEK="53" fi fi for i in ${HOST[@]} do directory_host=$DIRECTORY/$i/$WEEK 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 grep robots.txt $log_access | awk -F '|' '{print $3}' > $directory_host/robots_$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 else curl "ipinfo.io/$line?token=$TOKEN" >> $directory_host/output_$DATE.txt fi echo >> $directory_host/output_$DATE.txt done <$directory_host/list_$DATE echo "nombre de visite : $(wc -l $directory_host/list_$DATE |cut -d ' ' -f1)" > ${MAIL} echo "nombre de visite par pays, par region et par ville : " >> ${MAIL} LIST=("country" "region" "city") for j in ${LIST[@]} do echo "----${j}------" >> ${MAIL} cat $directory_host/output_$DATE.txt |grep "${j}" |sort |uniq -c >> ${MAIL} echo "--------------" >> ${MAIL} done ERROR=("400" "404") for j in ${ERROR[@]} do echo "nombre erreur ${j} par IP : " >> ${MAIL} cat $directory_host/${j}_$DATE |sort |uniq -c >> ${MAIL} echo "--------" >> ${MAIL} done echo "nombre de robots " >> ${MAIL} cat $directory_host/robots_$DATE |sort |uniq -c >> ${MAIL} echo "---------" >> ${MAIL} cat ${MAIL} |mail -s "Rapport reverse proxy $DATE" -A $directory_host/output_$DATE.txt valczebackup@gmail.com #rm $directory_host/* done