#!/bin/sh
-trap "exit 2" USR1
+trap "exit 1" USR1
err() {
printf "error: server not detected, needs to be set manually\n" >&2
# 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 -a "$@" | awk '{print $1}' | sort | uniq | xargs -L 1 host
+{ cat /var/log/"$SERVER"/access.log /var/log/"$SERVER"/access.log.1; gzip -cd $(ls /var/log/"$SERVER"/access.log.*.gz | sort -V); } | grep -a "$@" | awk '{print $1}' | sort | uniq | xargs -L 1 host
#!/bin/sh
-trap "exit 2" USR1
+trap "exit 1" USR1
err() {
printf "error: server not detected, needs to be set manually\n" >&2
# 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}'
+{ cat /var/log/"$SERVER"/access.log /var/log/"$SERVER"/access.log.1; gzip -cd $(ls /var/log/"$SERVER"/access.log.*.gz | sort -V); } | grep -a "$@" | awk 'match($0, /\" [0-9]{3} [0-9]+ \"/) { matchp = substr($0, RSTART, RLENGTH); split(matchp, nums, " "); n+=nums[3] } END {print n}'
CURDAY=$(tail -n1 /var/log/"$SERVER"/access.log | grep -oE "[0-9]{2}/.*/[0-9]{4}:")
-{ cat /var/log/"$SERVER"/access.log /var/log/"$SERVER"/access.log.1; gzip -cd /var/log/"$SERVER"/access.log.*.gz; } | awk -v curday="$CURDAY" '$0 ~ curday { if (match($0, /[0-9]{2}\/.*\/[0-9]{4}:[0-9]{2}:[0-9]{2}:[0-9]{2}/)) { print substr($0, RSTART, RLENGTH) } next } { exit }' | cut $CUTCMD | uniq -c | tail -n"$TAILN"
+{ cat /var/log/"$SERVER"/access.log /var/log/"$SERVER"/access.log.1; gzip -cd $(ls /var/log/"$SERVER"/access.log.*.gz | sort -V); } | awk -v curday="$CURDAY" '$0 ~ curday { if (match($0, /[0-9]{2}\/.*\/[0-9]{4}:[0-9]{2}:[0-9]{2}:[0-9]{2}/)) { print substr($0, RSTART, RLENGTH) } next } { exit }' | cut $CUTCMD | uniq -c | tail -n"$TAILN"
#!/bin/sh
-trap "exit 2" USR1
+trap "exit 1" USR1
err() {
printf "error: server not detected, needs to be set manually\n" >&2
# 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"/error.log.*.gz; cat /var/log/"$SERVER"/error.log /var/log/"$SERVER"/error.log.1; } | grep --color=auto -a "$@"
+{ cat /var/log/"$SERVER"/error.log /var/log/"$SERVER"/error.log.1; gzip -cd $(ls /var/log/"$SERVER"/error.log.*.gz | sort -V); } | grep --color=auto -a "$@"
#!/bin/sh
-trap "exit 2" USR1
+trap "exit 1" USR1
err() {
printf "error: server not detected, needs to be set manually\n" >&2
# 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 "$@"
+{ cat /var/log/"$SERVER"/access.log /var/log/"$SERVER"/access.log.1; gzip -cd $(ls /var/log/"$SERVER"/access.log.*.gz | sort -V); } | grep --color=auto -a "$@"