Skip to content

Latest commit

 

History

History
51 lines (39 loc) · 1.06 KB

scripts.md

File metadata and controls

51 lines (39 loc) · 1.06 KB
date title tags
2020-11-23 12:51:00 +0000
script
page

and also https://gist.github.com/f6o

common lisp for dummies

shell scripts

アクセスが多いIPを並べる

主に nginx 用デフォルトのログで先頭にIPアドレスがあればいい

awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -n | tail -n 5

nginxログ閲覧用スクリプト

#!/bin/bash
set -e

AWKSCRIPT='{print}'
case "$1" in
        "path" ) AWKSCRIPT='{print $7}' ;;
        "ip" ) AWKSCRIPT='{print $1}' ;;
esac

PRINT_LINES="5"
if [ -n "$2" ];
then
        PRINT_LINES="$2"
fi

pushd /var/log/nginx > /dev/null
cat access.log.1 access.log | awk "$AWKSCRIPT" | sort | uniq -c | sort -n | tail -n "$PRINT_LINES"
popd > /dev/null