-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.sh
More file actions
executable file
·27 lines (23 loc) · 1.02 KB
/
Copy pathparse.sh
File metadata and controls
executable file
·27 lines (23 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
for ip in $(cat /tmp/access.log | awk '{print $1}' | uniq -c | sort -nr | head -n5 | awk '{print $2}')
do
grep "$ip" /tmp/access.log >> /tmp/sort.log
done
# Send a mail to given email
SUBJECT="CRON INFO $(date +"%d/%m/%Y")"
# # This is a temp file, which is created to store the email message.
MESSAGE="/tmp/new-cron-logs.txt"
TO=""
echo "ip addres: $(cat /tmp/access.log | awk '{print $1}' | uniq -c | sort -nr | head -n5)" >> $MESSAGE
echo -e "\n" >> $MESSAGE
echo "+------------------------------+" >> $MESSAGE
echo "The site:" >> $MESSAGE
grep -oP "https*://([a-zA-Z]*){2,4}.(ru|com)/" /tmp/sort.log | uniq -c >> $MESSAGE
echo "+------------------------------+" >> $MESSAGE
echo "Who/Code/protocols:" >> $MESSAGE
awk '{print "method:"$6"\t""protocol:"$8"\t""code:"$9"\t""where:"$7}' /tmp/sort.log | sort -k4 | uniq -c | sort -rn >> $MESSAGE
echo "+------------------------------+" >> $MESSAGE
echo "ERRORS:" >> $MESSAGE
grep "$(date +"%H"):" /tmp/error.log >> $MESSAGE
mail -s "$SUBJECT" "$TO" < $MESSAGE
rm -f $MESSAGE