Last active
January 10, 2022 23:16
-
-
Save sophieforceno/509ae2fd2289d5406a2585b08d1a8512 to your computer and use it in GitHub Desktop.
Returns daily or all forbidden or refused requests parsed from the Nginx error log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
case "$1" in | |
all) | |
sudo grep -E "forb|refuse" /var/log/nginx/error.log | awk '{ print $1 " " $2 " " $11 }' | grep -w '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | tr -d ',' | |
# I also include a pipe to grep to remove all friendly IPs, something like: | |
# | grep -vE "192.168.1.*|$(curl -s ifconfig.co)|10.8.0.4" | |
;; | |
day) | |
sudo grep -E "forb|refuse" /var/log/nginx/error.log | awk '{ print $1 " " $2 " " $11 }' | grep -w '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | tr -d ',' | grep "$(date +%Y/%m/%d)" | |
;; | |
*) | |
cat << EOF | |
nginxfail.sh | |
Usage: nginxfail.sh [OPTIONS] <file> | |
all Return all forbidden & refused requests | |
day Return forbidden & refused requests for today | |
EOF | |
;; | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment