#!/bin/sh
-SERVER=$(which > /dev/null apache2 && printf "apache2" || which > /dev/null nginx && printf "nginx" || printf "ERROR: server not detected, needs to be set manually")
+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 -a "$@" | awk '{print $1}' | sort | uniq | xargs -L 1 host
#!/bin/sh
-SERVER=$(which > /dev/null apache2 && printf "apache2" || which > /dev/null nginx && printf "nginx" || printf "ERROR: server not detected, needs to be set manually")
+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)
[ "$1" -eq "$1" ] 2>/dev/null && NUM="$1" || NUM=30
#!/bin/sh
-SERVER=$(which > /dev/null apache2 && printf "apache2" || which > /dev/null nginx && printf "nginx" || printf "ERROR: server not detected, needs to be set manually")
+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"/error.log.*.gz; cat /var/log/"$SERVER"/error.log /var/log/"$SERVER"/error.log.1; } | grep --color=auto -a "$@"
#!/bin/sh
-SERVER=$(which > /dev/null apache2 && printf "apache2" || which > /dev/null nginx && printf "nginx" || printf "ERROR: server not detected, needs to be set manually")
+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 "$@"