From: git Date: Wed, 6 May 2026 20:04:21 +0000 (-0400) Subject: add countbytes X-Git-Url: https://git.datadissipation.net/?a=commitdiff_plain;h=a58ea8f04e9d780800df9f4c0a3454c1d717d046;p=logtools.git add countbytes --- diff --git a/countbytes b/countbytes new file mode 100755 index 0000000..e2691af --- /dev/null +++ b/countbytes @@ -0,0 +1,15 @@ +#!/bin/sh + +trap "exit 2" USR1 + +err() { + printf "error: server not detected, needs to be set manually\n" >&2 + printf "set \$SERVER or modify the script itself\n" >&2 + kill -USR1 "$$" +} + +# ... && ... || is not an if-then-else, but this works because +# there's no way for only one printf to fail +[ -z "$SERVER" ] && SERVER=$(which > /dev/null 2>&1 apache2 && printf "apache2" || which > /dev/null 2>&1 nginx && printf "nginx" || err) + +{ zcat /var/log/"$SERVER"/access.log.*.gz; cat /var/log/"$SERVER"/access.log /var/log/"$SERVER"/access.log.1; } | grep --color=auto -a "$@" | awk 'match($0, /\" [0-9]{3} [0-9]+ \"/) { matchp = substr($0, RSTART, RLENGTH); split(matchp, nums, " "); n+=nums[3] } END {print n}'