blob: 4b7986b3dba05fede2040360484346b08cfc4128 (
plain)
- #!/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
|