Skip to content

Instantly share code, notes, and snippets.

@oerdnj
Last active December 18, 2019 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oerdnj/e5d83df14667b252ebf766e9ebaf360e to your computer and use it in GitHub Desktop.
Save oerdnj/e5d83df14667b252ebf766e9ebaf360e to your computer and use it in GitHub Desktop.
#!/bin/sh
logfile=${1:-/var/log/nginx/packages.sury.org-access.log}
file_limit=480 # can go as low as 240 in the future
deb_limit=48 # can go as low as 24 in the future
perl -n -e '/^([^ ]+) ([^ ]+) ([^ ]+) (\[[^\]]+\]) "(.*) (.*) (.*)" ([0-9\-]+) ([0-9\-]+) "(.*)" "(.*)"/; print "$1 $6\n"' -- "$logfile" | sort | uniq -c | awk -v fl="$file_limit" dl="$deb_limit" '{ if ($1 > fl || (match($3,"\.deb") && $1 > dl)) { print $2 } }' | sort -u | xargs -i printf "deny %s;\n" "{}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment