summaryrefslogtreecommitdiff
path: root/localshowlogentries
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2008-02-03 22:09:07 +0000
committerJonas Smedegaard <dr@jones.dk>2008-02-03 22:09:07 +0000
commit31a2f897cfd72618879f348b9c6c63b6f317d2c5 (patch)
tree7af6d11513adb3907b1af052adce88268469ad24 /localshowlogentries
parent21f80eb17189a95f90f02af1cca52acb5bc31df5 (diff)
Rewrite to use common localshowlogentries.
Diffstat (limited to 'localshowlogentries')
-rwxr-xr-xlocalshowlogentries61
1 files changed, 61 insertions, 0 deletions
diff --git a/localshowlogentries b/localshowlogentries
new file mode 100755
index 0000000..4b7986b
--- /dev/null
+++ b/localshowlogentries
@@ -0,0 +1,61 @@
+#!/bin/sh
+#
+# /usr/local/sbin/localshowlogentries
+# Copyright 2007-2008 Jonas Smedegaard <dr@jones.dk>
+#
+# $Id: localshowlogentries,v 1.1 2008-02-03 22:09:07 jonas Exp $
+#
+# List recent log entries matching certain criteria
+#
+
+set -e
+
+output="${output:-shortline}"
+logfilecount="${logfilecount:-1}"
+pattern="${pattern:-user_dovecot}"
+
+searchstring="$1"
+egrep_before="$2"
+egrep_after="$3"
+sed_shortline="${4:-$sed_longline}"
+sed_msgid="$5"
+sed_qid="$6"
+sed_username="$7"
+sed_longline="${8:-s/^\(.\{15\}\) [^:]*: /\1 /}"
+sed_time="${8:-s/^\(.\{15\}\) .*$/\1 /}"
+
+case $output in
+ shortline)
+ sedstring="$sed_shortline"
+ ;;
+ msgid)
+ sedstring="$sed_msgid"
+ ;;
+ qid)
+ sedstring="$sed_qid"
+ ;;
+ username)
+ sedstring="$sed_username"
+ ;;
+ longline)
+ sedstring="$sed_longline"
+ ;;
+ time)
+ sedstring="$sed_time"
+ ;;
+ *)
+ echo >&2 "ERROR: unknwon output \"$output\""
+ exit 1
+ ;;
+esac
+
+if [ -z "$sedstring" ]; then
+ echo >&2 "ERROR: empty sed string for output \"$output\""
+ exit 1
+fi
+
+find /var/log -name 'mail.log*' | sort -nr -t. -k3 | tail -n "$logfilecount" | xargs zcat -f \
+ | egrep -- "$egrep_before$searchstring$egrep_after" \
+ | sed "$sedstring"
+
+exit 0