remove GNU-specific `sort -V`, fix log concatenation order for {,e}searchlog
[logtools.git] / esearchlog
index 5d2fe2718fe08c71162c4880c1a322f9813329f3..a9cc280967c93382611b623b734dfe01d07f9339 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-trap "exit 2" USR1
+trap "exit 1" USR1
 
 err() {
         printf "error: server not detected, needs to be set manually\n" >&2
@@ -12,4 +12,4 @@ err() {
 # 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 "$@"
+{ gzip -cd $(ls /var/log/"$SERVER"/error.log.*.gz | sed 's/.*\.\([0-9]*\)\.gz/\1 &/' | sort -rn | cut -d' ' -f2-); cat /var/log/"$SERVER"/error.log.1 /var/log/"$SERVER"/error.log; } | grep --color=auto -a "$@"