From 5462ac4b94232443c71cb4e8d438db0cad98a49a Mon Sep 17 00:00:00 2001 From: "E. S." Date: Mon, 8 Jan 2024 07:29:00 +0000 Subject: [PATCH] get-refs: add --full-files and --full-web options --- get-refs.sh | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/get-refs.sh b/get-refs.sh index 8b68684..566c312 100755 --- a/get-refs.sh +++ b/get-refs.sh @@ -1,9 +1,47 @@ #!/bin/bash source ~/.local/my/bash/bashrc -files="4in1.ws_access.log files.4in1.ws_access.log" -for f in $files; do - echo "> $f" - my_ssh root@4in1 cat "/var/log/nginx/$f" | awk '{print $11}' | grep -v 4in1.ws | sed 's/"//g' | sort | uniq +WEBSITE_LOG_FILENAME="4in1.ws_access.log" +FILES_LOG_FILENAME="files.4in1.ws_access.log" +FULL_WEB=0 +FULL_FILES=0 + +usage() { + echo "usage: $0 [--full-web] [--full-files] [-h|--help]" +} + +# Parse command-line arguments +while [ "$#" -gt 0 ]; do + case "$1" in + --full-web) + FULL_WEB=1 + shift + ;; + --full-files) + FULL_FILES=1 + shift + ;; + -h|--help) + usage + exit 0 + ;; + *) + 2>&1 echo "error: unknown option: $1" + usage + exit 1 + ;; + esac done + +# Execution branches +if [ "$FULL_WEB" = "1" ]; then + my_ssh root@4in1 cat "/var/log/nginx/$WEBSITE_LOG_FILENAME" | less +elif [ "$FULL_FILES" = "1" ]; then + my_ssh root@4in1 cat "/var/log/nginx/$FILES_LOG_FILENAME" | less +else + for f in $WEBSITE_LOG_FILENAME $FILES_LOG_FILENAME; do + echo "> $f" + my_ssh root@4in1 cat "/var/log/nginx/$f" | awk '{print $11}' | grep -v 4in1.ws | sed 's/"//g' | sort | uniq + done +fi