From 31a2f897cfd72618879f348b9c6c63b6f317d2c5 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 3 Feb 2008 22:09:07 +0000 Subject: Rewrite to use common localshowlogentries. --- localshowlogentries | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 localshowlogentries (limited to 'localshowlogentries') 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 +# +# $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 -- cgit v1.2.3