60 lines
2.0 KiB
Bash
Raw Permalink Normal View History

2023-01-22 20:51:28 +01:00
#!/bin/bash
2023-01-22 21:22:45 +01:00
MAIL=/tmp/mail
2023-01-22 20:51:28 +01:00
DIRECTORY=/home/valentin/mail
2023-01-22 21:07:54 +01:00
SERVER_LOG=/var/log/nginx
2023-02-12 22:28:32 +01:00
TOKEN=$(cat /etc/sentinel/token)
2023-01-22 20:51:28 +01:00
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)
2023-01-23 23:45:51 +01:00
if [ ${#WEEK} -eq 1 ]; then
WEEK="0${WEEK}"
fi
2023-01-22 20:51:28 +01:00
else
WEEK="53"
fi
fi
for i in ${HOST[@]}
do
directory_host=$DIRECTORY/$i/$WEEK
2023-01-22 21:07:54 +01:00
log_access=${SERVER_LOG}/${i}_access.log.1
2023-01-22 20:51:28 +01:00
mkdir -pv $directory_host
cat $log_access | grep "|" | awk -F "|" '{print $1}' | sort | uniq > $directory_host/list_$DATE
2023-01-22 21:07:54 +01:00
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
2023-02-16 23:06:03 +01:00
grep robots.txt $log_access | awk -F '|' '{print $3}' > $directory_host/robots_$DATE
2023-01-22 20:51:28 +01:00
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
2023-01-22 21:07:54 +01:00
done <$directory_host/list_$DATE
2023-01-22 21:22:45 +01:00
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}
2023-01-22 20:51:28 +01:00
LIST=("country" "region" "city")
for j in ${LIST[@]}
do
2023-01-22 21:22:45 +01:00
echo "----${j}------" >> ${MAIL}
cat $directory_host/output_$DATE.txt |grep "${j}" |sort |uniq -c >> ${MAIL}
echo "--------------" >> ${MAIL}
2023-01-22 20:51:28 +01:00
done
2023-01-22 21:07:54 +01:00
ERROR=("400" "404")
for j in ${ERROR[@]}
do
2023-01-22 21:22:45 +01:00
echo "nombre erreur ${j} par IP : " >> ${MAIL}
cat $directory_host/${j}_$DATE |sort |uniq -c >> ${MAIL}
echo "--------" >> ${MAIL}
2023-01-22 21:07:54 +01:00
done
2023-02-16 23:06:03 +01:00
echo "nombre de robots " >> ${MAIL}
cat $directory_host/robots_$DATE |sort |uniq -c >> ${MAIL}
echo "---------" >> ${MAIL}
2023-01-22 21:22:45 +01:00
cat ${MAIL} |mail -s "Rapport reverse proxy $DATE" -A $directory_host/output_$DATE.txt valczebackup@gmail.com
2023-01-22 20:51:28 +01:00
#rm $directory_host/*
done