Created
June 5, 2023 18:40
-
-
Save ConnerWill/844c3506264dae72eab6058fd851a881 to your computer and use it in GitHub Desktop.
Helper script to start nginx log analyzer goaccess
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 | |
## Function to simply pipe nginx logs to goaccess | |
function _goaccessnginx(){ | |
user_input="${1}" | |
[[ "${user_input}" == "html" ]] | |
## Save screen contents and clear screen | |
tput smcup && clear | |
## Set trap to restore screen contents and return if Ctrl + C is pressed | |
trap 'clear; printf "\e[0;1;38;5;196mEXITING ... \e[0m\n"; sleep 0.25; tput rmcup; return' SIGINT | |
## Invalidate sudo timestamp file | |
sudo --reset-timestamp | |
## Print password prompt text | |
printf "\e[0;38;5;190m(goaccess)\e[0;38;5;241m:\e[0;38;5;46m ENTER SUDO PASSWORD \e[0;38;5;201m[:>\e[0m" | |
## Refresh the time limit on sudo without running a command | |
sudo --validate --prompt=" " | |
## Uncompress log files and pipe the output to goaccess | |
sudo zcat /var/log/nginx/access* | sudo goaccess /var/log/nginx/access.log - | |
## Restore screen contents | |
tput rmcup | |
} | |
## Call '_goaccessnginx' function | |
_goaccessnginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment