a6bd11daf91a5437df5d5b9e4798d5366871fb73
[logtools.git] / searchlog
1 #!/bin/sh
2
3 trap "exit 2" USR1
4
5 err() {
6 printf "error: server not detected, needs to be set manually\n" >&2
7 printf "set \$SERVER or modify the script itself\n" >&2
8 kill -USR1 "$$"
9 }
10
11 # ... && ... || is not an if-then-else, but this works because
12 # there's no way for only one printf to fail
13 [ -z "$SERVER" ] && SERVER=$(which > /dev/null 2>&1 apache2 && printf "apache2" || which > /dev/null 2>&1 nginx && printf "nginx" || err)
14
15 { zcat /var/log/"$SERVER"/access.log.*.gz; cat /var/log/"$SERVER"/access.log /var/log/"$SERVER"/access.log.1; } | grep --color=auto -a "$@"