add script sentinel
This commit is contained in:
parent
e5a64b1846
commit
5915385fea
45
roles/deploy-web/files/getinfo_day.sh
Executable file
45
roles/deploy-web/files/getinfo_day.sh
Executable file
@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
DIRECTORY=/home/valentin/mail
|
||||
TOKEN=af920d2f7dbe97
|
||||
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)
|
||||
else
|
||||
WEEK="53"
|
||||
fi
|
||||
fi
|
||||
for i in ${HOST[@]}
|
||||
do
|
||||
directory_host=$DIRECTORY/$i/$WEEK
|
||||
log_access=/var/log/nginx/${i}_access.log.1
|
||||
mkdir -pv $directory_host
|
||||
cat $log_access | grep "|" | awk -F "|" '{print $1}' | sort | uniq > $directory_host/list_$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)" > /tmp/mail
|
||||
echo "nombre de visite par pays, par region et par ville : " >> /tmp/mail
|
||||
LIST=("country" "region" "city")
|
||||
for j in ${LIST[@]}
|
||||
do
|
||||
echo "----${j}------" >> /tmp/mail
|
||||
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
|
||||
cat /tmp/mail |mail -s "Rapport reverse proxy $DATE" -A $directory_host/output_$DATE.txt valczebackup@gmail.com
|
||||
#rm $directory_host/*
|
||||
done
|
1
roles/deploy-web/files/virtualhost
Normal file
1
roles/deploy-web/files/virtualhost
Normal file
@ -0,0 +1 @@
|
||||
clarissa
|
Loading…
x
Reference in New Issue
Block a user