Add summary

This commit is contained in:
Brice Waegeneire 2020-10-09 17:42:51 +02:00
parent 3447439d54
commit 35e33d2d51

View file

@ -1,6 +1,6 @@
#!/bin/sh
# TODO total by host: vhost, htaccess, conf, cgi
# TODO Use \0 as a seprator
set -e
@ -57,7 +57,7 @@ get_template() {
template_dirs="/etc /usr/share/scripts"
grep -RE '^[[:space:]]*(Order|Allow|Deny|Satisfy)[[:space:]]' \
--exclude-dir=apache2 --exclude-dir=squid3 "$template_dirs" \
2>/dev/null
|| true
}
# Put different type of configs in different files
@ -75,6 +75,7 @@ count_directives() {
for directive in $directives; do
export "$directive"="$(grep -Ec "^[[:blank:]]*$directive\\s" "$1")"
done
# FIXME: There are probably a lot of flase negative
export CGI="$(grep -Ec "^[[:blank:]]*# CGI" "$1")"
# shellcheck disable=SC2154
@ -110,11 +111,36 @@ display_results() {
# One line machine summary of the results
display_summary() {
# Types: Vhost, System, Htaccess
printf 'Vhost\tSystem\tHtaccess\tTotal\tCGI\n' >&2
# Types: Vhost, System, Htaccess, Template
printf 'Hostname:\tVhost\tSystem\tHtaccess\tTemplate\tTotal\tCGI\n' >&2
printf "%s " "$(hostname)"; awk -f - "$result" <<EOF
BEGIN {
total["V"] = 0;
total["S"] = 0;
total["H"] = 0;
total["T"] = 0;
cgi = 0;
}
{
total[\$NF] += \$(NF-2);
cgi += \$(NF-1);
}
END {
print total["V"] " " \
total["S"] " " \
total["H"] " " \
total["T"] " " \
total["V"] + total["S"] + total["H"] + total["T"] " " \
cgi;
}
EOF
}
get_confs
categorize_confs
display_results
# display_summary
display_summary